PHP upload file to web server from form. error mes

2019-09-02 15:30发布

I am trying to upload a file from a php form. I have verified the target location with my ISP as being "/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

$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

4条回答
叼着烟拽天下
2楼-- · 2019-09-02 15:40

Check folder names, they should be case sensitive, and also check if POD folder has 777 rights(CHMOD)

查看更多
Animai°情兽
3楼-- · 2019-09-02 15:45

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/

查看更多
太酷不给撩
4楼-- · 2019-09-02 15:48

Agreed with Phil, remove the space between string and file name

"/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);
查看更多
The star\"
5楼-- · 2019-09-02 16:01

There is an error in your code:

You need to change your move_uploaded_file funciton. 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. If you din't put quotes PHP will take it as constants. 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 :)

查看更多
登录 后发表回答