Home  >  Article  >  Backend Development  >  PHP文件上传异常

PHP文件上传异常

WBOY
WBOYOriginal
2016-06-13 13:52:42972browse

PHP文件上传错误
我用这个代码在WINDOWS上传文件成功,但到LINUX下失败了,请帮我看看什么原因,以下是代码:

――――u1.htm――――




upfile






――――u1.php――――


$uploadaction=0;
$timelimit=0;
set_time_limit($timelimit);

$uploaddir = '/root/file/';
$uploadfile = $uploaddir.$_FILES['userfile']['name'];
$tmpfile = $_FILES['userfile']['tmp_name'];
$file_size = $_FILES['userfile']['size'];
$errno = $_FILES['userfile']['error'];
echo "The uploadfile is $uploadfile";
echo "The tmpfile is $tmpfile";

  if(!file_exists($uploadfile))
  {
  if(move_uploaded_file($tmpfile,$uploadfile))
  {
  echo "The file $uploadfile($strfilesize)upload successful!";
  }
  else
  {
  echo"The file$uploadfile upload failed(error code:$errno)";
  }


  }


  set_time_limit(30);

?>

运行后错误是:upload failed(error code:0) 


------解决方案--------------------
你的程序没有问题,应当是php.ini配置文件的问题。
------解决方案--------------------
chmod($uploaddir,"777")
文件权限.....
------解决方案--------------------
$errno = $_FILES['userfile']['error'];
其值为 0,没有错误发生,文件上传成功。


你看下move_uploaded_file($tmpfile,$uploadfile)里面的参数路径是否正确,且有读写权限
------解决方案--------------------
/tmp有空间吗?
selinux是否关掉?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn