Hi, I was just wondering if there is a way of putting a newly created image into the db without creating the image on the harddrive first. Here is my shortend code:
If the user did not specify an image, a default “no pic” image is created. $image is then put into the db. The problem is that I have to create “temp.pic” first with imagejpeg(). Can’t I skip this step and somehow put $im into $image?
I just thought its unnecessary overhead. My other concern is that another user might change the temp.pic between
imagejpeg($im, “temp.pic”); and
$image = addslashes(file_get_contents(“temp.pic”));
To prevent the wrong pic being send to the db I’m thinking of adding a random number to the name e.g.
…
$temp = rand().“temp.pic”;
imagejpeg($im, $temp);
…
but then I will have to destroy it every time.
(How do I do that again?..)
by the way ,whats point here storing file in database rather than file system?
any specific requirements?
otherwise article like “storing file in filesystem v/s database” may come handy
There are different arguments for and against putting files in the database; easier backups, cleaner folders, more control over who sees what etc. I’m still learning and at the moment the main reason for me was to see if I could do it.
no problems…
but
easier backup…
many server do have certain limitations on size of the file that can be back at once…so it will actually a problem and harder to backup once your image grow in number
plus image folder backup using ftp or other tools is much easier i guess than downloading 100mb sql file
cleaner folder
it depends upon how much have structured…if you have structure in proper way,it will rather help to find the exact file and will be much cleaner
control who see it
even if you store file filesystem you will have corresponding row for it in database (without binary image)…so i dont think this advantage applies…ie you can track it with out storing binary file as well
plus big problem
if image is big,it will make database and query slow significantly which will be very harmful for you application
and there are many others…
may be reading some more article will help u…