Hello all,
I am familiar with php and mysql coding. I learned most of my php/mysql coding from the sitepoint book “how to build database driven websites using php and mysql.” Great book! Really simplified my learning. However, I have never done any coding with images.
My dilemma is first trying to figure out if the best way to upload images is to store them in a folder or in the database as a BLOB.
The next dilemma is how do I add the primary key custnum (auto-incremented) to the images that are uploaded so they can be queried later? Everything been going smoothly until I ran into this image upload issue.
Generally speaking you store images on the file system, not in databases - but you store its address in your database. (Do some reading on the subject if you like : [google]when should images be stored in a database[/google])
That address might well become “/images/23.jpg” which is what you seem to be alluding to.
On successful upload, you would a) move the image from the /tmp directory and b) store it somewhere on your file system.
All you need to do between those operations is to enter a new row into your table - perhaps with some other descriptive text from the upload operation? the file type (jpg, bng, gif etc) or the date of upload maybe?
As the new entry is made you ask mysql for the last inserted id number, which you allocate as the file name.
So far, I have the images being stored in the upload_images folder. The pics are being named whatever the user had them named, which is fine. I am just confused as to how I label the pictures the user number that mysql auto generates.
I would like for the user to enter their info, upload their pictures (up to 12), resize them to 500 pixels wide, then somehow stamp the pictures with the mysql_last_insert_id. I like the method of storing the location in the database. But at some point, I need to be able to search by user number to pull up all the users pictures.
Currently, the webpage inserts the user info to the user table. Then I pull the unique user number from the user table. I want to figure out how I label the uploaded pics with the last_id from the user table.