PHP move_uploaded_file错误

时间:2011-07-04 09:45:25

标签: php upload

localhost win7 xampp 上运行,此代码出现错误

$source = $_FILES['fupload']['tmp_name'];
$upload_dir = "invform/upload/";
 if (file_exists($upload_dir) && is_writable($upload_dir)) {
       move_uploaded_file( $source, $upload_dir ) or die ("Couldn't copy");
  }
  else {
        die ('Upload directory is not writable, or does not exist.');
  }

错误是Couldn't copy表示目录是可写的

$source是:D:\\xampp\\tmp\\phpFB1.tmp

会出现什么问题?

3 个答案:

答案 0 :(得分:4)

move_uploaded_file的目标应为文件名

$source = $_FILES['fpupload']['tmp_name'];
$upload_dir = "invform/upload/";
$dest = $upload_dir.$source; // gives: invform/upload/phpFB1.tmp

检查手册上的move_uploaded_file

答案 1 :(得分:4)

试试这个,你错过了目标目录中的文件名

    $source = $_FILES['fupload']['tmp_name'];
    $upload_dir = "invform/upload/";
     if (file_exists($upload_dir) && is_writable($upload_dir)) {
           move_uploaded_file( $source, $upload_dir.$_FILES['fupload']["name"]  ) or die ("Couldn't copy");
      }
      else {
            die ('Upload directory is not writable, or does not exist.');
      }

答案 2 :(得分:2)

尝试针对http://php.net/manual/en/features.file-upload.errors.php检查$_FILES['fupload']['error']条目 move_uploaded_file()可能由于不可写目标目录以外的原因而失败(即如果表单没有正确的enctype属性,则文件将无法正确上传)