PHP从表单上传文件到Web服务器。错误信息

时间:2012-01-30 04:46:14

标签: php forms file upload

我正在尝试从php表单上传文件。 我已经通过我的ISP验证了目标位置为“/ home / hulamyxr / public_html / POD /”

执行页面时出现以下错误:

Warning: move_uploaded_file(/home/hulamyxr/public_html/POD/ 1511.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/hulamyxr/public_html/hauliers/include/capturelocal2.php on line 124

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpyp3ERS' to '/home/hulamyxr/public_html/POD/ 1511.pdf' in /home/hulamyxr/public_html/hauliers/include/capturelocal2.php on line 124
POD Successfully uploaded for delivery 1511. filename: :

我的表格代码

<form enctype="multipart/form-data" method="post" action="capturelocal2.php">
<input type=file size=6 name=ref1pod id=ref1pod>
</form>

我的PHP代码上传文件

$ref1 = $_POST[ref1]; //this is the name I want the file to be
$ref1pod = $_POST[ref1pod]; // this is the name of the input field in the form

  move_uploaded_file($_FILES["ref1pod"]["tmp_name"],
  "/home/hulamyxr/public_html/POD/ " . ($ref1.".pdf"));

非常感谢任何帮助。 感谢致敬, 莱恩史密斯

4 个答案:

答案 0 :(得分:3)

您的代码中存在错误:

您需要更改move_uploaded_file功能。我认为有一个额外的空间导致了这个问题:

move_uploaded_file($_FILES["ref1pod"]["tmp_name"],"/home/hulamyxr/public_html/POD/" .($ref1.".pdf"));

我也不确定

在哪里
$ref1 = $_POST[ref1]; //this is the name I want the file to be
$ref1pod = $_POST[ref1pod];

来自。你的表格中没有这样的价值观。您是否仅上传了仅包含上传的表单。另外,请务必在表单中放置属性值的引号并发布值。

ref1和ref1pod是常量吗?如果你不加引号,PHP将把它作为常量。如果它们不是常数,则改为:

$ref1 = $_POST['ref1']; //this is the name I want the file to be
$ref1pod = $_POST['ref1pod'];

同样在您的表单中,加上引号:

<form enctype="multipart/form-data" method="post" action="capturelocal2.php">
     <input type="file" size="6" name="ref1pod" id="ref1pod"/>
</form>

请务必为上传文件夹设置权限。

希望这可以帮助你:)

答案 1 :(得分:1)

检查文件夹名称,它们应区分大小写,并检查POD文件夹是否具有777权限(CHMOD)

答案 2 :(得分:1)

同意Phil,删除字符串和文件名之间的空格

"/home/hulamyxr/public_html/POD/ " . ($ref1.".pdf"));
                                ^
                                |

您还可以尝试以下方法:

$ref1 = $_POST[ref1];
$file_name = $_SERVER['DOCUMENT_ROOT'] . '/POD/' . $ref1 . '.pdf';
move_uploaded_file($_FILES['ref1pod']['tmp_name'], $file_name);

答案 3 :(得分:1)

请尝试以下代码。

 <?php
 if(isset($_REQUEST['upload'])) {
   $filename    =   $_FILES['ref1pod']['tmp_name'];
   if (file_exists($_SERVER['DOCUMENT_ROOT']."/POD/".$_FILES["ref1pod"]["name"]))
       {
        echo $_FILES["ref1pod"]["name"] . " Already Exists. ";
       }
      else {
   $path = $_SERVER['DOCUMENT_ROOT']."/POD/".$_FILES['ref1pod']['name'];
       move_uploaded_file($filename,$path);         
  }
}
?>

<form enctype="multipart/form-data" method="post" action="">
 <input type=file size=6 name=ref1pod id=ref1pod>
 <input type="submit" name="upload" value="upload" />
</form>

http://patelmilap.wordpress.com/2012/01/30/php-file-upload/