简体   繁体   English

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

[英]PHP upload file to web server from form. error message

I am trying to upload a file from a php form. 我正在尝试从php表单上传文件。 I have verified the target location with my ISP as being "/home/hulamyxr/public_html/POD/" 我已经通过ISP验证了目标位置为“ / home / hulamyxr / public_html / POD /”

I get the below error when executing the page: 执行页面时出现以下错误:

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: :

My Form Code 我的表格代码

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

My PHP Code to upload the file 我的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"));

Any assistance will be greatly appreciated. 任何帮助将不胜感激。 Thanks and Regards, Ryan Smith 谢谢和问候,瑞安·史密斯

There is an error in your code: 您的代码中有错误:

You need to change your move_uploaded_file funciton. 您需要更改您的move_uploaded_file功能。 There is an extra space i think which is causing the problem: 我认为有多余的空间导致了问题:

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

Also i am not sure where is the 我也不确定

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

coming from .There is no such values in your form. 来自。您的表单中没有这样的值。 Did you upload only the form with upload only. 您是否仅上传了带有仅上传的表格。 Also be sure to put quotes around attribute values in your form and post value. 另外,请务必在表单中的属性值前后加上引号,然后发布值。

Is ref1 and ref1pod are constants. ref1和ref1pod是常量。 If you din't put quotes PHP will take it as constants. 如果您不使用引号,PHP会将其视为常量。 If they are not constants change to: 如果它们不是常数,则更改为:

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

Also in your form, put quotes: 同样以您的形式,用引号引起来:

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

Be sure you set permissions to your upload folder . 确保对上传文件夹设置了权限。

Hope this helps you :) 希望这对您有所帮助:)

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

Agreed with Phil, remove the space between string and file name 与Phil达成协议,删除字符串和文件名之间的空格

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

and you can also try the following : 您还可以尝试以下操作:

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

Please try following code. 请尝试以下代码。

 <?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/ http://patelmilap.wordpress.com/2012/01/30/php-file-upload/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM