943,526 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 778
  • PHP RSS
Oct 13th, 2008
0

Multiple upload assigning specific names

Expand Post »
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['pic1']['tmp_name'], 'pics/picture.jpg');

Repeating this three times (with pic2, pic3, pic4) doesn't seem to work.
Any ideas?
Last edited by twmprys; Oct 13th, 2008 at 6:35 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
twmprys is offline Offline
8 posts
since Oct 2008
Oct 13th, 2008
0

Re: Multiple upload assigning specific names

Quote ...
move_uploaded_file($_FILES['pic1']['tmp_name'], '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 ['pic1'] 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:
php Syntax (Toggle Plain Text)
  1. <?
  2. $image=imagecreatefromjpeg($_FILES['uploadedfile']['name']);
  3. ?>
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.
Last edited by cwarn23; Oct 13th, 2008 at 8:21 am. Reason: code tags
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Oct 13th, 2008
0

Re: Multiple upload assigning specific names

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.

Click to Expand / Collapse  Quote originally posted by cwarn23 ...
The reason why that didn't work is because the array ['pic1'] 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:
php Syntax (Toggle Plain Text)
  1. <?
  2. $image=imagecreatefromjpeg($_FILES['uploadedfile']['name']);
  3. ?>
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
twmprys is offline Offline
8 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Sessions: cookies and use_trans_sid
Next Thread in PHP Forum Timeline: meta tags in php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC