Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iphong

macrumors member
Original poster
Aug 28, 2004
66
0
Washington, DC
So, I try to do a very basic upload 101 with PHP using HTML form. But I can't get it to work.

HTML file submit the file to a PHP file,

in the PHP file i try to debug by doing this

PHP:
echo 'File name:' . $_FILES['uploadedfile']['name'];
echo 'Temp name:' . $_FILES['uploadedfile']['tmp_name'];

the $_FILES['uploadedfile']['name'] returns blank, it means that file wasn't sent to server somehow. I tried to create a tmp folder in the root folder but it doesn't resolve the problem.

Any ideas to make this work? By the way, my codes work on my other Yahoo! hosted server, but not on this local server.

here is the script that I made to quick test. The actual code I used in my applications is too complicated to be posted here.

PHP:
$target_path = "upload/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

echo 'File name:' . $_FILES['uploadedfile']['name'] . '<br>'; 
echo 'Temp name:' . $_FILES['uploadedfile']['tmp_name'] . '<br>';

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
 
If your stuff works on a different server, I suspect your php.ini file is setup differently. Check to make sure uploading is allowed and that the max file size is bigger than the file you're trying to upload.
 
Also make sure the permissions are set correctly in the upload and target paths on the server. This might mean chmod 777 for those directories, but the previous advice given by NoNameBrand is superb so check that first.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.