使用PHP上传PDF文件失败

时间:2012-12-05 09:31:12

标签: php file-upload

我无法上传我的PDF文件,即使我已尝试过谷歌的一些提示。 但是,我的PHP上传仍然无法正常工作。我已将文件夹权限更改为777

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
<input type="hidden" name="MAX_FILE_SIZE" value="3500000" />
Upload File: <input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>

$target_path = "/home/jeinqa/www/apps/upload/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
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!";
                }

显示: There was an error uploading the file, please try again!


尝试使用print_r($_FILES);

Array ( [uploadedfile] => Array ( [name] => SOP-31 KW-HDR81BTJD.pdf [type] => [tmp_name] => [error] => 2 [size] => 0 ) ) There was an error uploading the file, please try again!

1 个答案:

答案 0 :(得分:1)

  1. 您的文件夹是否具有777权限(以及所有子文件夹)?
  2. 您是否在PHP.ini中启用了safe_mode?
  3. 您的MAX_FILE_SIZE是10 KB,但我怀疑您的文件是否很小,请检查您的文件大小。
  4. target_path是否存在?
  5. 尝试将target_path从绝对更改为相对,它可能会变为:upload。
  6. <强>更新

    你的档案很大!只需更改最大尺寸! 有关详细信息,请参阅http://php.net/manual/en/features.file-upload.errors.php

    您的错误:价值:2;上传的文件超出了HTML表单中指定的MAX_FILE_SIZE指令。