Link to home
Start Free TrialLog in
Avatar of cgustaf
cgustaf

asked on

PHP UPLOAD ERROR...

I am trying to use the following script, but it produces a persistent error (as noted below the script.  Maybe the issue is naming a temp directory, but I am unable to determine this.  Here is the scrpt and the error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
 
<body>
 <?php // RAY_upload_example.php
error_reporting(E_ALL);
 
// MANUAL REFERENCE PAGES
// http://docs.php.net/manual/en/features.file-upload.php
// http://docs.php.net/manual/en/features.file-upload.common-pitfalls.php
// http://docs.php.net/manual/en/function.move-uploaded-file.php
// http://docs.php.net/manual/en/function.getimagesize.php
 
// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY
$uploads = '/upload';
 
// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT
$max_file_size = '8192000';  // EIGHT MEGABYTE LIMIT ON UPLOADS
 
// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
// $file_exts = array('jpg', 'gif', 'png', 'txt');
$file_exts = array('rtf');
 
// ESTABLISH THE NUMBER OF FILES WE CAN UPLOAD
// $nf = 3;
$nf = 1; 
 
 
// THIS IS A LIST OF THE POSSIBLE ERRORS THAT CAN BE REPORTED IN $_FILES[]["error"]
$errors&#9;= array(
&#9;0 => "Success!",
&#9;1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini",
&#9;2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
&#9;3 => "The uploaded file was only partially uploaded",
&#9;4 => "No file was uploaded",
&#9;6 => "Missing a temporary folder",
&#9;7 => "Cannot write file to disk"
);
 
 
 
// IF THERE IS NOTHING IN $_POST, PUT UP THE FORM FOR INPUT
if (empty($_POST))
{
&#9;?>
&#9;<h2>Upload <?=$nf?> file(s)</h2>
 
&#9;<!--
&#9;&#9;SOME THINGS TO NOTE ABOUT THIS FORM...
&#9;&#9;NOTE THE CHOICE OF ENCTYPE IN THE HTML FORM STATEMENT
&#9;&#9;MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
&#9;&#9;INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
&#9;-->
 
    <form name="UploadForm" enctype="multipart/form-data" action="<?=$_SERVER["../../../REQUEST_URI"]?>" method="POST">
&#9;<input type="hidden" name="p" value="1" />
&#9;<input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
&#9;<p>
&#9;Find the file(s) you want to upload and click the "Upload" button below.
&#9;</p>
 
&#9;<?php for ($n = 0; $n < $nf; $n++)
&#9;&#9;{
&#9;&#9;&#9;echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
&#9;&#9;}
&#9;?>
&#9;<br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <b>overwrite</b> existing files.
&#9;<input type="submit" name="_submit" value="Upload" />
&#9;</form>
&#9;<?php
&#9;die();
}
 
 
 
else // WE HAVE GOT SOMETHING IN $_POST
{
 
// THERE IS POST DATA - PROCESS IT
&#9;echo "<h2>Results: File Upload</h2>\n";
 
// ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>\n";
 
// ITERATE OVER THE CONTENTS OF $_FILES
&#9;foreach ($_FILES as $my_uploaded_file)
&#9;{
 
// SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
&#9;&#9;$error_code&#9;= $my_uploaded_file["error"];
&#9;&#9;if ($error_code == 4) continue;
 
// SYNTHESIZE THE NEW FILE NAME
&#9;&#9;$f_type&#9;= trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
&#9;&#9;$f_name&#9;= trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
&#9;&#9;$my_new_file = getcwd() . '/' . $uploads . '/' . $f_name .'.'. $f_type;
&#9;&#9;$my_file     = $uploads . '/' . $f_name .'.'. $f_type;
 
// OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
&#9;&#9;if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");
 
// IF THERE ARE ERRORS
&#9;&#9;if ($error_code != 0)
&#9;&#9;{
&#9;&#9;&#9;$error_message = $errors[$error_code];
&#9;&#9;&#9;die("Sorry, Upload Error Code: $error_code: $error_message");
&#9;&#9;}
 
// GET THE FILE SIZE
&#9;&#9;$file_size&#9;= number_format($my_uploaded_file["size"]);
 
// MOVE THE FILE INTO THE DIRECTORY
// IF THE FILE IS NEW
&#9;&#9;if (!file_exists($my_new_file))
&#9;&#9;{
&#9;&#9;&#9;if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;$upload_success = 1;
&#9;&#9;&#9;}
&#9;&#9;&#9;else
&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;$upload_success = -1;
&#9;&#9;&#9;}
 
// IF THE FILE ALREADY EXISTS
&#9;&#9;}
&#9;&#9;else
&#9;&#9;{
&#9;&#9;&#9;echo "<br/><b><i>$my_file</i></b> already exists.\n";

 
// SHOULD WE OVERWRITE THE FILE? IF NOT
&#9;&#9;&#9;if (empty($_POST["overwrite"]))
&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;$upload_success = 0;
 
// IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
&#9;&#9;&#9;}
&#9;&#9;&#9;else
&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;$now&#9;= date('Y-m-d');
&#9;&#9;&#9;&#9;$my_bak = $my_new_file . '.' . $now . '.bak';
&#9;&#9;&#9;&#9;if (!copy($my_new_file, $my_bak))
&#9;&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;&#9;echo "<br/><b>Attempted Backup Failed!</b>\n";
&#9;&#9;&#9;&#9;}
&#9;&#9;&#9;&#9;if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
&#9;&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;&#9;$upload_success = 2;
&#9;&#9;&#9;&#9;}
&#9;&#9;&#9;&#9;else
&#9;&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;&#9;$upload_success = -1;
&#9;&#9;&#9;&#9;}
&#9;&#9;&#9;}
&#9;&#9;}
 
// REPORT OUR SUCCESS OR FAILURE
&#9;&#9;if ($upload_success == 2) { echo "<br/>It has been overwritten.\n"; }
&#9;&#9;if ($upload_success == 1) { echo "<br/><b><i>$my_file</i></b> has been saved.\n"; }
&#9;&#9;if ($upload_success == 0) { echo "<br/><b>It was NOT overwritten.</b>\n"; }
&#9;&#9;if ($upload_success < 0)  { echo "<br/><b>ERROR <i>$my_file</i> NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</b>\n"; }
&#9;&#9;if ($upload_success > 0)
&#9;&#9;{
&#9;&#9;&#9;echo "$file_size bytes uploaded.\n";
&#9;&#9;&#9;if (!chmod ($my_new_file, 0755))
&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;echo "<br/>chmod(0755) FAILED: fileperms() = ";
&#9;&#9;&#9;&#9;echo substr(sprintf('%o', fileperms($my_new_file)), -4);
&#9;&#9;&#9;}
&#9;&#9;&#9;echo "<br/><a href=\"$my_file\">See the file $my_file</a>\n";
&#9;&#9;}
// END ITERATOR
&#9;}
}
?> 
 
</body>
</html>


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
RUNNING THE ABOVE CODE PRODUCES THE FOLLOWING ERROR.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Results: File Upload
 array(1) {
  ["userfile0"]=>
  array(5) {
    ["name"]=>
    string(6) "HI.rtf"
    ["type"]=>
    string(18) "application/msword"
    ["tmp_name"]=>
    string(37) "/services/webdata/phpupload/php6UMJgQ"
    ["error"]=>
    int(0)
    ["size"]=>
    int(4621)
  }
}
array(3) {
  ["p"]=>
  string(1) "1"
  ["MAX_FILE_SIZE"]=>
  string(7) "8192000"
  ["_submit"]=>
  string(6) "Upload"
}

Open in new window


ERROR /upload/hi.rtf NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND
Avatar of jouwstrm
jouwstrm
Flag of United States of America image

Are you getting the error in move_uploaded_file()?
If so this looks like a permissions issue.
Whats the server you are running this on? Windows? Linux?

If its windows, I know you need to allow access to the temp folder so windows can move the file from temp to the directory you specified.
Avatar of cgustaf
cgustaf

ASKER

It appears the error is in the move_uploaded_file() function.  The error message says:

ERROR /upload/hi.rtf NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND

which indicates the error is in/from this function.

The server is on Linux, a shared server.  II have set the directory to 777, but this does not help.  I don't know, however, exactly where in the script the temp directory is designated.  Therefore I may not have the temp directory correctly set up on the server.

If youi could show me in the script where the temp directory is designated, and how the script should be edited to alllow for, say \upload\tempdir\ on the server, I'd be grateful.

Here is a simple php upload form , if you need a upload form this is simplest one ;

<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" value="Upload" />
</form>

Open in new window


<?php
   $file = current($_FILES) ;
   move_uploaded_file($file['tmp_name'],"/myuploadfolder/".$file['name']) ;
?> 

Open in new window

I don't have much expierience with Linux.
So not sure if this would make a difference.

From your error message, it looks like your temp directory is
/services/webdata/phpupload/

I would check your permissions on that directory.

Mike
Avatar of cgustaf

ASKER

I have tried the sugggested simple upload script, but there is no telling whether it works or not.  In other words, I do not see to where the file is uploaded if it is indeed uploaded at all.

The help I need on this should be more detailed.  That is, a more informed and detailed analysis of the script I originally sent is need in order to fully understand why it fails.
*** edited by Mod_MarlEE, Tue 17 May 2011, 19:10 EST ***

The problem is with move_uploadded_file(), meaning its already on your system. It just needs to move from the temp directory, to the directory you specified. Which usually means permissions.

Mike
Curt: regarding this:
ERROR /upload/hi.rtf NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND

Have you got a line number for that?

Here in no particular order are some thoughts that come to mind.  

When I posted the script, it did not have the extraneous HTML at the top.  You might want to remove that, or move it some place that makes more sense.

The script assumes that the $uploads variable gives the name of an existing directory that is in the web root directory tree.

My guess is that the directory named /upload/ does not have permissions that will let PHP write into it.  In most shared-server configurations PHP runs as "nobody" and so you need to give write permission to "nobody" for things to work out correctly.

It may also be that you want to use upload instead of /upload/ - I would try it without the slashes around the directory name.

Is the upload target directory part of the directory tree in your web root?  If so, specifying the first slash may cause the server to look for a file on the same level as public_html instead of a file inside the tree of public_html.

Are you sure that the upload directory already exists?

HTH, ~Ray
Avatar of cgustaf

ASKER

Thanks, Ray -- I'm looking at this now, and will let you know the outcome.
Avatar of Eddie Shipman
It seems to be a PATH issue.
Are you sure trying to move a file to /upload/hi.rtf?
/upload is off the system root, not the web root

Avatar of cgustaf

ASKER

I have now installed a simple script which works:

<form action="upload_simple.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" value="Upload" />
</form>
<?php
   $file = current($_FILES) ;
   move_uploaded_file($file['tmp_name'], $file['name']) ;
?>
The URL to run this is:
http://clgus.com/upload/upload_simple.php

I have also tried to run the comprehensive script uploaded by Ray.  Now it only reports HTML error 500.

The URL to run this is:
http://clgus.com/upload/upload_r.php

The CHMOD on the upload directory is 777.

Hoping to find a solution.  The features of Ray's script are useful, and I'd like to apply it if possible.

One of the great things about PHP is that whenever you are not sure how a function works, you can look it up.  Example:

move_uploaded_file($file['tmp_name'], $file['name']) ;

See the man page here: http://us3.php.net/manual/en/function.move-uploaded-file.php

So when I run your script, I believe it would move the uploaded file to the destination given in $file['name'] and that destination would be relative to the the upload directory.  That may or may not be what you want.  For example, I just uploaded a file named "upload_simple.php" and it overwrote the existing PHP script.

I was unable to reproduce the 500 error - I got a blank screen.  Maybe that script is still a moving target.

Suggest you start building the script up bit-by-bit so you understand each step in the process.  You can use var_dump() to print out variables like $_POST and $_FILES.  And before your server gets hacked, change the script so it does not upload into its own directory - if you leave it the way it is, you are making certain that catastrophe is not left to chance!
Avatar of cgustaf

ASKER

Ray -- I have struggled with the HTTP 500 error, and finally contacted the ISP since I understand this error is server related.  Here is the reply:

Laura B.: i enabled errors for that folder and now you can see that issue is coding related and unfortunately we do not provide assistance with any coding issues
Laura B.: Parse error: syntax error, unexpected '&' in /services8/webpages/util/i/b/ibtpartners.site.aplus.net/public/upload/upload_r.php on line 26

Perhaps you have some comments or advice on this.
Yes, please ensure that you have these statements at the top of the script.

ini_set('display_errors', TRUE);
error_reporting(E_ALL);

Then we should be able to see the error messages in the browser output stream.  Most PHP error messages have a line number.  For example, line number 26 in the script posted with this question says this:

$file_exts = array('rtf');

So we know that the script posted with this question is not the same script that created the parse error unexpected '&' on line 26.

Not sure what your depth of experience is with PHP, but you might find this book to be of value:
http://www.sitepoint.com/books/phpmysql4/

Best regards, ~Ray
Avatar of cgustaf

ASKER

Thank you for replying.

I entered the error reporting code which resulted in this:

Parse error: syntax error, unexpected '&' in /services8/webpages/util/i/b/ibtpartners.site.aplus.net/public/upload/upload_r.php on line 28

Here is line 28:
&#9;0 => "Success!",

There are of course many ampersands in the script.  The first one now occurs on line 28, but there are many more down to line 171.
Every occurrence of &#9; should be replaced by a tab character or by 4 spaces.  This looks like an artifact of a copy-and-paste error or some sort.  A new copy of my teaching script is in the code snippet.  HTH, ~Ray
<?php // RAY_upload_example.php
error_reporting(E_ALL);


// MANUAL REFERENCE PAGES
// http://php.net/manual/en/features.file-upload.php
// http://php.net/manual/en/features.file-upload.common-pitfalls.php
// http://php.net/manual/en/function.move-uploaded-file.php


// PHP 5.1+  SEE http://us3.php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY
$uploads = 'RAY_junk';

// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT - ABOUT 8 MB
$max_file_size = '8192000';

// ESTABLISH THE MAXIMUM NUMBER OF FILES WE CAN UPLOAD
$nf = 3;

// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
$file_exts = array
( 'jpg'
, 'gif'
, 'png'
, 'txt'
, 'pdf'
)
;

// LIST OF THE ERRORS THAT MAY BE REPORTED IN $_FILES[]["error"] (THERE IS NO #5)
$errors = array
( 0 => "Success!"
, 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini"
, 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"
, 3 => "The uploaded file was only partially uploaded"
, 4 => "No file was uploaded"
, 5 => "UNDEFINED ERROR"
, 6 => "Missing a temporary folder"
, 7 => "Cannot write file to disk"
)
;




// IF THERE IS NOTHING IN $_POST, PUT UP THE FORM FOR INPUT
if (empty($_POST))
{
    ?>
    <h2>Upload <?php echo $nf; ?> file(s)</h2>

    <!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        ENCTYPE IN THE HTML <FORM> STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
        ABSENCE OF ACTION= ATTRIBUTE IN FORM TAG CAUSES POST TO SAME SCRIPT
    -->

    <form name="UploadForm" enctype="multipart/form-data" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php // CREATE INPUT STATEMENTS FOR UP TO $n FILE NAMES
    for ($n = 0; $n < $nf; $n++)
    {
        echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
    }
    ?>

    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <strong>overwrite</strong> existing files.
    <input type="submit" value="Upload" />
    </form>
    <?php
    die();
}
// END OF THE FORM SCRIPT



// WE HAVE GOT SOMETHING IN $_POST - RUN THE ACTION SCRIPT
else
{
    // THERE IS POST DATA - PROCESS IT
    echo "<h2>Results: File Upload</h2>\n";

    // ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
    //    echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>\n";

    // ITERATE OVER THE CONTENTS OF $_FILES
    foreach ($_FILES as $my_uploaded_file)
    {
        // SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
        $error_code    = $my_uploaded_file["error"];
        if ($error_code == 4) continue;

        // SYNTHESIZE THE NEW FILE NAME
        $f_type    = trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
        $f_name    = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
        $my_new_file = getcwd() . '/' . $uploads . '/' . $f_name . '.' . $f_type;
        $my_file     =                  $uploads . '/' . $f_name . '.' . $f_type;

        // OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
        if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");

        // IF THERE ARE ERRORS
        if ($error_code != 0)
        {
            $error_message = $errors[$error_code];
            die("Sorry, Upload Error Code: $error_code: $error_message");
        }

        // GET THE FILE SIZE
        $file_size = number_format($my_uploaded_file["size"]);

        // IF THE FILE IS NEW (DOES NOT EXIST)
        if (!file_exists($my_new_file))
        {
            // IF THE MOVE FUNCTION WORKED CORRECTLY
            if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
            {
                $upload_success = 1;
            }
            // IF THE MOVE FUNCTION FAILED
            else
            {
                $upload_success = -1;
            }
        }

        // IF THE FILE ALREADY EXISTS
        else
        {
            echo "<br/><b><i>$my_file</i></b> already exists.\n";

            // SHOULD WE OVERWRITE THE FILE? IF NOT
            if (empty($_POST["overwrite"]))
            {
                $upload_success = 0;
            }
            // IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
            else
            {
                $now    = date('Y-m-d');
                $my_bak = $my_new_file . '.' . $now . '.bak';
                if (!copy($my_new_file, $my_bak))
                {
                    echo "<br/><strong>Attempted Backup Failed!</strong>\n";
                }
                if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
                {
                    $upload_success = 2;
                }
                else
                {
                    $upload_success = -1;
                }
            }
        }

        // REPORT OUR SUCCESS OR FAILURE
        if ($upload_success == 2) { echo "<br/>It has been overwritten.\n"; }
        if ($upload_success == 1) { echo "<br/><strong>$my_file</strong> has been saved.\n"; }
        if ($upload_success == 0) { echo "<br/><strong>It was NOT overwritten.</strong>\n"; }
        if ($upload_success < 0)  { echo "<br/><strong>ERROR: $my_file NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</strong>\n"; }
        if ($upload_success > 0)
        {
            echo "$file_size bytes uploaded.\n";
            if (!chmod ($my_new_file, 0755))
            {
                echo "<br/>chmod(0755) FAILED: fileperms() = ";
                echo substr(sprintf('%o', fileperms($my_new_file)), -4);
            }
            echo "<br/><a href=\"$my_file\">See the file $my_file</a>\n";
        }
    // END FOREACH ITERATOR - EACH ITERATION PROCESSES ONE FILE
    }
}

Open in new window

Avatar of cgustaf

ASKER

OK -- I will work with this verision of the script, and hope to get it going.  I thought all those ampersands looked odd!
Avatar of cgustaf

ASKER

Here is what I find:  There is a "begin php" marker (<?php) on line 79 in the above script.  But I don't find a corresponding "end php" marker (?>) anywhere.  So I added line 184 and put ?> there.  That seemed to fix the script.

But I'm still having trouble with line 125, the move_uploaded_file() function.  I think the problem is understanding ['tmp_name'].  Should ['tmp_name']  be left as it is, or should it be replaced with something else?

The same question probably applies to line 155.
The close-PHP tag is only needed if you have non-PHP material following it.  Omitting this tag is a Zend coding standard and there are many good reasons to leave it out, so I do that.

['tmp_name'] should be left as it is.  It's hard wired into the $_FILES array.  See the man page here:
http://us3.php.net/manual/en/function.move-uploaded-file.php

In this script $my_uploaded_file['tmp_name'] refers to one element of the $_FILES array.

The script I posted in the snippet above is available on my server at this URL.  I periodically discard the contents of the RAY_junk folder, so feel free to try it out.
http://www.laprbass.com/RAY_upload_example.php
Avatar of cgustaf

ASKER

Thanks -- I removed the final ?>, and made sure ['tmp_file'] is there. When I run the file I get this error:

Results: File Upload

Warning: move_uploaded_file(/services8/webpages/util/i/b/ibtpartners.site.aplus.net/public/upload/upload/seat selection complaint.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in /services8/webpages/util/i/b/ibtpartners.site.aplus.net/public/upload/upload_r3.php on line 127

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/services/webdata/phpupload/phpPfUzz4' to '/services8/webpages/util/i/b/ibtpartners.site.aplus.net/public/upload/upload/seat selection complaint.txt' in /services8/webpages/util/i/b/ibtpartners.site.aplus.net/public/upload/upload_r3.php on line 127

ERROR: upload/seat selection complaint.txt NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND

Which is about the same as where we were from the beginning.  The error has to do with the move uploaded file function..

On path issue that I see is that it duplicates the /upload/ directory in the upload to path:
'/services/webdata/phpupload/phpPfUzz4' to '/services8/webpages/util/i/b/ibtpartners.site.aplus.net/public/upload/upload/seat selection complaint.txt'

In the /public directory, there is only one /upload directory.  What might be generating this second /upload directory in the upload to path?
Try removing the blanks from the file name.  Make it something like seat_selection_complaint.txt
BTW - what OS and release of PHP are you using here?
Avatar of cgustaf

ASKER

Inside the /public/upload/ directory, I added an /upload/ directory so that the structure would correspond to the path, which is:  

to '/services8/webpages/util/i/b/ibtpartners.site.aplus.net/public/upload/upload/seat_selection_complaint.txt'  

where, as you see, there are two levels of /upload/upload/ .  Though this solution is sort of "Mickey Mouse" since I don't understand, yet, where that second /upload/ directory comes from, at least the upload script now works.

The structure definitely was /public/upload/ while the generated path was /public/upload/upload/ .  

Could there be an explanation for this?

To test the "fix" I used a file whose name was without spaces, so I don't know it that was critical or not.  But definitely, adding an /upload/ directory inside the top /upload/ directory solved the problem.  Sot was a matter of path.

The PHP on the shared server is version 5, but I don't know the exact release.

Thank you for your help.  If you have some thouights on why the dual \upload\upload\ directories appear in the generated path, I'd appreciate hearing from you.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cgustaf

ASKER

My shared server is Linux, and I work in Windows.
I think I should be able to figure out what's going on with the path from your example.  Thank you.
I am awarding the points now.


Avatar of cgustaf

ASKER

Grateful for your expert help!
Thanks for the points.  I would still appreciate it if you can tell me the version number of PHP you are using.  I want to run some tests on file uploads with different versions.  Thanks and best regards, ~Ray
Avatar of cgustaf

ASKER

This is a response to a question asked by Ray Paseur:

The PHP version on my server is 5.2.13.

Thank you,

Curt L. Gustafsson
Thanks, Curt.