Page 1 of 1

MySQL - Storing images?

Posted: Fri Feb 07, 2003 4:18 pm
by Exdaix
How would I use a form to upload images to a MySQL table?

Posted: Fri Feb 07, 2003 6:43 pm
by fractalvibes
First of all, make sure you have a field in your table defined as a BLOB
(Binary Large OBject)

You form tag will look like this:
<form method="post" name="frmUpload" action="fileupload.php" ENCTYPE="multipart/form-data">

The form element where they select the file to upload:
<input type="file" name="txtTheFile"> - that generates a "Browse" button for them to choose the file from their local file system.

After that it is little more than inserting the file via Sql.

Phil J.

images

Posted: Sat Feb 08, 2003 2:46 am
by phpScott
Unless you have real a really solid reason for wanting to store images in a db I generally find it to much of a hassel, and takes up to much space unless there are real restrictions on the size of the images to be stored.

My appoaroch is to just store the name of the image in the db and then use that to to create the src in the <img > tag.

you still need to do the same thing as fractalvibes said about the form and input tags. But you will need to copy the file to your images directory as it just gets copied to the tmp directory on the server.

phpScott
If you want a sample script on how to do this just post and I will send you a copy of mine.

Posted: Sat Feb 08, 2003 9:34 am
by Exdaix
That sounds great phpScott, so what you do is upload the images to a directory with the POST form, and copy thier names to a table in the database? I think I am understanding it alright.

Could you post that code?

Thank you for your time.

Posted: Sun Feb 09, 2003 1:20 am
by fractalvibes
Yes, much as phpScott said - most of the time you are better off just storing the link to the image rather than the image itself. There do arise occasions where storing in the database makes sense - Apps on two different servers that needed to pull from a common set of images, neither could see each other's file systems, a question of replication or using a common database they could each talk to...

Phil J.

Posted: Sat Feb 15, 2003 12:33 pm
by Exdaix
phpScott... you there?