PHP/MYSQL - Image

Associate
Joined
14 May 2008
Posts
130
Hi, was wondering if someone can direct me on how i can do this if possible as im looking to update my mother in laws as a semi xmas gift and so its a tad easier for her to manage (and i get a lot of calls from her too =p)

Basically i was wondering how i would go about storing an image in a mysql db, i know how to upload it to a server etc where it would be stored but no idea how to save the image path to the db or how to display this in a query aswell and have it at a certain size say 400*300~

Anyone got any tips/guides that can explain / help me on this?

Kind regards
Is7doji
 
Rather than storing the image in SQL it is better to store the filename. Much easier to work with and more future proof.

For resizing PHP can be used with GD and Imagemagick. The latter one is my personal favourite.
 
The only time I recommend storing anything in a database is office docs in SQL Server as it can index their content.

As others have said, move the uploaded file (possibly resizing it too) into your images folder and bung that path/filename combo into a varchar field.
 
aye kinda guessed that the filename would be faster/better but how would i go about it since i was thinking of a simple upload for for her.

field one
image to upload from her pc to server which would prob be /uploads/images/filname.type so would need to grap the extension /name of this file
field two
field three
 
you can store the encoded string in a DB. If would be more cost efficient on your HD space on your hosting plan to use it in this fashion than by storing the images, were your images particularly large

Besides, why not do it like this? I know it is a bit of effort alright, but it is good programming practice, and the OP did ask for it
 
Last edited:
Thanks for the input, ive gone with the storing the filename in the db, ive got the displaying it correctly but having a few problems graping the filename/extension

the code ive tried

Code:
$sql="INSERT INTO concept_art (id_number, name, image)
VALUES
('','$_POST[name]','.$HTTP_POST_FILES['ufile']['name'].')";

but i seem to get the error with this

Code:
'.$HTTP_POST_FILES['ufile']['name'].'

anyone got any sugesstions?

Kind regards
Is7doji
 
Like to say thanks for your input, got it working the way i want =D
Just need a little help as im adding a bit more functionality to it, so wondering how i would add a lnk(url) to where the image is so when they click the image it will show the full image in the browser. Had a look at silverlight i think it was which i will add later but for now i was just want it in the browser.

this is the code i have for my image to display so guessing i would have to add the <a>url$row</a> in there i think, havent tried it yet tho

Code:
echo '<img src=' . $row["example"] . ' width="400" height="200">';

Kind regards
Is7Doji
 
I would generate the filenames yourself, or at least append a unique string, rather than relying on the filename of the uploaded image/file, as it's quite likely people will try to upload multiple files with the same name (especially if using a digital camera which resets its filenames when emptying the memory card!)
 
Back
Top Bottom