>백엔드 개발 >PHP 튜토리얼 > 用file下传文件,在tmp目录上找不到文件

用file下传文件,在tmp目录上找不到文件

WBOY
WBOY원래의
2016-06-13 13:15:031045검색

用file上传文件,在tmp目录下找不到文件
代码如下:








upload.php
if ($_FILES["file"]["error"] > 0)
{
  echo "Return Code: " . $_FILES["file"]["error"] . "
";
}
else
{
  echo "Upload: " . $_FILES["file"]["name"] . "
";
  echo "Type: " . $_FILES["file"]["type"] . "
";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
";
  echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
";

  if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " already exists. ";
  }
  else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  }
 }
?>

运行结果:
Upload: jdk-6u34-windows-x64.exe
Type: application/octet-stream
Size: 61154.484375 Kb
Temp file: F:\xampp\tmp\phpCB11.tmp

Warning: move_uploaded_file(upload/jdk-6u34-windows-x64.exe): failed to open stream: No such file or directory in F:\xampp\htdocs\test\qwe.php on line 26

Warning: move_uploaded_file(): Unable to move 'F:\xampp\tmp\phpCB11.tmp' to 'upload/jdk-6u34-windows-x64.exe' in F:\xampp\htdocs\test\qwe.php on line 26
Stored in: upload/jdk-6u34-windows-x64.exe 

纠结好久了,平台环境是windows平台下安装XAMPP集成环境
望高手解答,并且想知道是为什么……



------解决方案--------------------
目录 upload 不存在
------解决方案--------------------
可能原因:
1.路径不对。
2.文件夹没有权限。
加 dirname(__FILE__) 看看。 


if (file_exists(dirname(__FILE__)."/upload/" . $_FILES["file"]["name"]))
------解决方案--------------------
failed to open stream: No such file or directory
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.