I am building a website where models and photographers can regsiter a profile. During registration I am wanting to allow a maximum of 6 images to be uploaded. However, I want to either append the file name with the name of the user, so the image stored on the server will be called

$USERID_<photo file>.<ext>

or create a folder on the fly to store the images in so the location will be

<UPLOAD LOCATION>/$USERID/<photo file>.<ext>.

The USERID, file location and file name also need to be stored in MySQL.

I have a script which I have borrowed from a tutorial, and I have tested this script and it works, allowing me to upload a single image to a pre-defined location and store the data in MySQL. But I need to change the script to allow for the above [max 6 images, and renamed file or location].

Note: register_globals is OFF.

Can anyone help me please? If you know of a good script or if you can point me in the direction of a tutorial which covers all of this I would be very grateful. I am new to PHP and MySQL but I want to learn. I can post the files I have from the tutorial if this helps.

For reference, I am also wanting to create a profile page on the fly [i.e. have a page created immediately after registration where the details entered are displayed for each member], and the ability to search the database. I mention this in case there is a total solution, but I want to deal with and learn one thing at a time, so my question is only for the image upload problem.

Recommended Answers

All 5 Replies

Are you inserting image inside the mysql database?

Are you inserting image inside the mysql database?

No, just the file location and a few other bits of data. The physical image file needs to be uploaded to a pre-determined location or to a directory created on the fly and named after the USERID.

I understand it is a bad to store the image in the database, although I know this can be done using "blob".

if i'm not mistaken you're having trouble uploading multiple images... is that it?

you know you can search that in google something like "PHP multiple file upload" and you will find your answer.

if i'm not mistaken you're having trouble uploading multiple images... is that it?

No. I have a script that works. It uploads the image to a pre-determined location, but it only uploads one image. Again, that isn't the problem as I know there are scripts out there that I can search for for multiple uploads.

The problem I have is that I want to rename the file after it is uploaded, or create a folder - naned after the user - for the image to go into.

The reason I need this is so that I can tell what images belong to which user. So I have to either create a folder before the image is uploaded, naming it after the $USERID [/$USERID/], or place the images all in one folder, and append the name with the $USERID variable [USERID$_filename.ext]

Does that make sense now?

to fix your problem, just have all of the images upload into the same directory with a randomly generated name. then put that name into the database (which i think you have already done) with the member id.

to get the images for a member, just run a query on the images table that will select all image name with a specific member id. simple.

if you don't want to do it that way, you are going to have to post the code for the upload so we can make the changes. no one will be able to help until this is done, because we won't know how the code is setup to make the changes. we are not psychic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.