what's wrong with the upload code?
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none) {
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) {
echo "Successful<BR/>";
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
开发者_C百科 //$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
echo "<img src="$path" width="150" height="150">";
} else {
echo "Error";
}
}
?>
it is an toturial form here http://tutorialblog.info/2010/08/06/php-upload-single-file.html when i tried in my local environment. it displays an error? what's wrong with the code? thank you.
first, i think this is wrong. if($ufile !=none)
it should be if($_POST['ufile' !=none)
am i right?
I agree with Stephen, this is not a good example, you also need to validate your upload. you are not going to allow anyone to upload anything.
but if you want just find the issues: well HTTP_POST_FILES is no longer accepted by PHP newer versions. should be $_FILES
$ufile !=none can be if ($_FILES['ufile']['tmp_name'])
copy($HTTP_POST_FILES['ufile']['tmp_name'], $path) better be move_uploaded_file($_FILES['ufile']['tmp_name'], $path)
Your html form enctype should be enctype="multipart/form-data"
the $path path should have the right permission
精彩评论