0

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

1
  • 1
    Does the POD directory exist and is it writable by the PHP script? You can use is_dir() and is_writable() to check. Also, why the space between POD/ and the destination file? You really shouldn't allow the user to choose a filename without at least some form of validation Commented Jan 30, 2012 at 4:51

4 Answers 4

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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);

Comments

1

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.