cakephp finding multiple images and displaying them (possibly outside webroot?) - cakephp

I am currently trying to build a cakephp app that will list items from a database, and there is a field in the database named picture. This picture field contains a string which is the primary picture, so for example ABCD, and then in the images folder this is ABCD.jpg
However there is usually various extra pictures for this particular item, which may be named ABCD1 or ABCD_2 or some other such variating suffix. I had previously written some script in php which used a glob function and counted the files and outputted them.
I am seriously struggling to do this in cakephp, at the moment there is several thousand images stored in the webroot of the server in /images and I understand that cake will be looking in the webroot of the app like /app/webroot, so is it possible to view their original location? or must they be moved...
I have read a little about the file and folder classes but I am struggling to comprehend them, not sure if my brains failed me here or if this is actually a difficult concept..
my question is how would I find any files that begin with this prefix in the picture field after selecting by the id of the item, to then display all those that match for that particular item?
thanks for your help!

Not a real answer to your question but you should start making a database relationship with your pics.
Check out hasMany to make a relationship between your Article (or whatever it is) and the Picture models. Now you will not have to look for each filename, as you'll have it in your database.

Related

Translating text direcly from DB using .po file

I've been having this problem for several days, after reseaching, I haven't found a solution.
I'm on a cakePHP 2.5.6 project, and I'm on the internationalization right now, everything seemed to work just fine, but I came across this issue:
In my DB I store several tags for my articles, the problem is that the name of the tag is given to me by a query directly from the DB, and printed using a foreach.
Here is my doubt, is there any way to translate those fields using my .po file?
I have thought some solutions but I'm trying to avoid them because I think they are just lame, such as create a new column in my tags table with the translated name in it.
CakePHP's pot files are generated for hard-coded strings in template files and elsewhere in your app. Basically anything like __('Hello'), it doesn't work if you use variables like __($var) as it needs to know the string to generate the translation files.
If the content is coming from the database you need to look at translating the database content within the database as you've suggested. Rather than create a new set of columns on your tags table you should look into using CakePHP's Translate behaviour. Cake's Translate behaviour should do what you are looking for without you needing to re-invent the wheel.

Database vs static html files for storage solution (Site Builder)

Project Description:
As a learning exercise for asp mvc 4, I'm creating a site builder / multitenancy site. It's nothing too fancy just wysiwyg editing on templates with custom routing to direct users to the correct template based on subdomain. So usr1.mysite.com is directed to the template edited by usr1. My main concern at the moment is my method of storing the edited templates.
Storage Dilemma:
At first I was simply going to make the templates into views and store the changes made by the user in the database. When usr1's template was displayed the system would pull up the view and populate it with usr1's data.
Instead I've implemented a system that takes the user's modified template and saves the whole thing as static html files in the file system. Only the path to the usr1's site (and some other details) are saved in the database. When usr1.mysite.com is called I just have a "content" controller to retrieve the correct html file.
Question:
Is there any reason to choose the database/view method over the static html file method?
Also I'm not concerned with having dynamic content in the end user pages. This is one reason I even tried the file method.
Decision (EDIT):
I'm implementing the file method. After more research (verifying my previous research), I have few doubts the file system will have trouble with even a few hundred sites. I will structure it in a way to group user data directories into group directories based on a naming convention I've yet to dream up, probably something like 000usr1, 000usr2 in 000 group directory. With a goal of less than 100 files/folders in any given directory and less than 4 levels deep. Which should give me the capability of holding 10000 sites. I have no plans of having any activity near that level with this software, but I do want to get up and running and torture it for awhile and see what it's capable of handling. If anyone expresses any interest I'll post back some results.

Storing Images in SQL Server database

I'm trying to create a sample ASP.NET MVC application with a ViewModel and onion architecture - very simple online shop.
So as you suppose this shop has products, and each product should have one very small image and when user clicks on that product, he is redirected to a details page, and of course he should see a bigger image of the product.
AT first I thought, it's a simple application, I would (internet) links to the pictures in the database. But then I thought, ok what about when this image is erased from internet, my product will no longer have an image.
So I should store those pictures in the database somehow. I have heard about something called FileStream that is the right way but I found no material to understand what is that.
I hope someone would help me.
There are several options. You could save the picture in the database using a varbinary.
Read here how to read it using MVC.
When you opt for a solution where you split database and file storage, which is perfectly possible, you should consider that it could mean extra maintenance for cross-checking deleted records, etc.
If you choose the last option, the information in the article will mostly suite your needs too.

Automatically apprend or prepend names of files uploaded with date or random number in SharePoint

I have somehow turned into the person to oversee my organization's SharePoint and I have been tasked with finding a way that when a file is uploaded to any of our document libraries the file name of said file is either prepended, appended with a date or random string in an effort to prevent naming collisions.
I understand that SharePoint will block uploading files with the same name but I would like to just apprend or prepend a date or string to the file name to just bypass the whole issue. Our users aren't the most tech savvy so to automatically rename their files for them would help us and them both.
Is there a way to do this currently in SharePoint's settings? I've looked into versioning and Document ID but neither prevent the naming issues so far. Is there a plug-in of some sort I could use? or do I need to have code written by someone and have it added to SharePoint?
Thanks!
The Content Organizer feature of SharePoint 2010 allows you to set a duplicate submissions tag to documents.
"Duplicate Submissions
This option specifies whether to use SharePoint versioning or append unique characters to the end of duplicate file names if a document is uploaded that has the same name as a document that is already in the destination library."
Play around with this to see if it is going to help before worrying about a more complex coded solution. Your users may also appreciate the drop box approach to document uploading.

HABTM association not being saved?

I'm attempting to create a simple 'tags' type of setup, allowing admins to 'tag' an image so it shows up in certain places. I've only started development and wanted to tackle this portion first. I literally just finished running bake, so everything at the moment is standard and I haven't touched any of the generated code.
I have three tables - Tags, Images, and Images_Tags. When I hit /images/add I see the tags I've created listed in a nice multi-select box. I enter the info, select some tags, hit submit. Once saved, I'm redirected to the index and I noticed there are no tags listed for the image I just created. Digging deeper, there are no records in the Images_tags table either.
I'm thinking something is off with my model, or I have a bad database column name somewhere that's borking the default methodology.
Any ideas where I could look? I'm a newbie to cakePHP, go easy on me :)
Here are a couple of things to look at.
From the sounds of things, the images are not being saved. This means that if images are not being saved, nothing will appear in the images_tags table. So the images create/save feature needs to be looked at more closely.
To troubleshoot this, since you have not touched the code, use scaffolding:
var $scaffold;
in the top of the controller and try adding the image again. See if that will allow you to add images. Typically, when something like this happens, its because the schema for the table has changed after baking all of the functionality for the table.

Resources