The online racing simulator
PHP image upload script question
(13 posts, started )
PHP image upload script question
I am trying to upload 4 images at once. First time trying this script or anything like it. Anyone let me know where i'm going wrong. it will only upload the 1st file. It 'dies' when trying the 2nd.

PHP CODE

<?php 
    copy 
($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) or die ("Could not copy file 1");      
copy ($_FILES['imagefile1']['tmp_name1'], "files/".$_FILES['imagefile1']['name']) or die ("Could not copy file 2");      
copy ($_FILES['imagefile2']['tmp_name2'], "files/".$_FILES['imagefile2']['name']) or die ("Could not copy file 3");      
copy ($_FILES['imagefile3']['tmp_name3'], "files/".$_FILES['imagefile3']['name']) or die ("Could not copy file 4")
?>

Prob something obvious but i'm a PHP n00b!
Can anyone help?
-
(thisnameistaken) DELETED by thisnameistaken
Your problem doesn't lie with anything in the code snippet!
Do you get any error messages when it "dies"?
What the PHP timeout set to?
Does the webserver have a timeout?
Quote from the_angry_angel :Do you get any error messages when it "dies"?
What the PHP timeout set to?
Does the webserver have a timeout?

I dont get any error messages because i told it to print "Could not copy file 2" and so on..
Looking through my phpInfo() page i couldn't find anything on timeout except these:
Quote :mysql.connect_timeout 60

Quote :default_socket_timeout 60

it couldn't be a timeout problem because the file sizes are 18k each and its usually a quick server.
Firstly, try ...

<?php 
print_r
($_FILES);
?>

... before that code snippet to make sure that the data for file 2 is actually there.

If it is there (and you are using a PHP > 4.2.0), try changing


<?php 
die("Could not copy file 2")
?>

to

<?php 
die($_FILES['imagefile1']['error'])
?>

and lookup the result here ...
http://www.php.net/manual/en/features.file-upload.errors.php

That might give you more clue as to what is occuring.
result of print_r($_FILES);

Quote :Array ( [imagefile] => Array ( [name] => uploadTest-1.jpg [type] => image/jpeg [tmp_name] => /tmp/phpmIw4Dv [error] => 0 [size] => 18696 ) [imagefile1] => Array ( [name] => uploadTest-2.jpg [type] => image/jpeg [tmp_name] => /tmp/phpjwJ8La [error] => 0 [size] => 18696 ) [imagefile2] => Array ( [name] => uploadTest-3.jpg [type] => image/jpeg [tmp_name] => /tmp/phpozmKiZ [error] => 0 [size] => 18696 ) [imagefile3] => Array ( [name] => uploadTest-4.jpg [type] => image/jpeg [tmp_name] => /tmp/phpjg1rYc [error] => 0 [size] => 18696 ) )

result of die($_FILES['imagefile1']['error'])
Quote :Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/carInsert.php on line 15

any help?
ehehe, I see it, and all of y'all saying there is nothing wrong with that code sample need a clout on the beak

You are suffixing the number on to tmp_name; you don't need to. Thats the reason the first works and the rest dont

I.E. imagefile1 source location should look like

<?php 
$_FILES
['imagefile1']['tmp_name']
?>

and imagefile2 source location should look like

<?php 
$_FILES
['imagefile2']['tmp_name']
?>

This kinda looks like one of those errors in the Zend cert guide
excellent! thank you Anarchi-H ....
was kinda obvious in the end. i though i had to give 4 different temporary names but i forgot one is executed before moving onto the other
:doh: Once again Anarchi makes me feel dumb
-
(thisnameistaken) DELETED by thisnameistaken
Quote from the_angry_angel ::doh: Once again Anarchi makes me feel dumb

Hehe, don't feel bad... I've my fair share of *doh* moments too, only mine tend to be catastropic ones.... like writing a $500 backend for someone in ASP , using classes, only to find out that they are on a crappy old version of chillisoft that doesn't have classes

Now that really made me feel stupid.
Just a tip: when you're dealing with file uploads, be sure to check whether the file extension is valid. A php file that has an image in it will pass all the standard image checks and will also display the image, but will still execute code that might follow the image, leaving you wide open to attacks
Quote from the_angry_angel ::doh: Once again Anarchi makes me feel dumb

You're not the only one he made feel dumb

Quote from sil3ntwar :I think copy is really only meant for copying files from one directory on the webserver to another. try using the move_uploaded_file function as it is meant for handling file uploads. Its what i use on my site and it works perfectly.

However, copy() is still perfectly valid for uploading files, however it was depricated with the introduction of move_uploaded_file() in PHP 4.0.3 But, personally, I use move_uploaded_file() now.

PHP image upload script question
(13 posts, started )
FGED GREDG RDFGDR GSFDG