Hello, hope someone can help. I've created a simple interface for a website owner to carry out very limited editing. On the first page, there's a form which uploads just one picture to a picture folder and inserts text into a database field. That works fine. Now I need to create a new page with a form where you can choose four pictures with corresponding text. The text works OK, that just inserts into four separate fields in a database. I hoped I could simply duplicate the picture upload script (changing the input names each time), but it doesn't work. (Please note that the pictures have to overwrite existing ones, so they appear on the website - that's is why I specify the precise path).

This is the picture input script:
move_uploaded_file($_FILES, 'pics/picture.jpg');

Repeating this three times (with pic2, pic3, pic4) doesn't seem to work.
Any ideas?

Recommended Answers

All 2 Replies

move_uploaded_file($_FILES, 'pics/picture.jpg');

Repeating this three times (with pic2, pic3, pic4) doesn't seem to work.

The reason why that didn't work is because the array refers the the name of the file browse field in your html form. So what you put in 'pic1' should be the same as what you put in the type='file' field. This then brings the question of how to load the image multiple times. To solve the issue of loading the file multiple times, use the following code:

<?
$image=imagecreatefromjpeg($_FILES['uploadedfile']['name']);
?>

Then the image is stored in the variable $image where it can be used by the gd library. Note you may want to alter the imagecreatefrom*() to the appropriate supported format.

Thank you for this, but I'm not loading the same image more than once - there are four different images to be loaded, they just overwrite existing images. There are four fields in the form for the images: pic1, pic2, pic3 and pic4. None of them are being passed up to the site, whereas there isn't a problem with the form with just one image.

The reason why that didn't work is because the array refers the the name of the file browse field in your html form. So what you put in 'pic1' should be the same as what you put in the type='file' field. This then brings the question of how to load the image multiple times. To solve the issue of loading the file multiple times, use the following code:

<?
$image=imagecreatefromjpeg($_FILES['uploadedfile']['name']);
?>

Then the image is stored in the variable $image where it can be used by the gd library. Note you may want to alter the imagecreatefrom*() to the appropriate supported format.

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.