Reply to topic
PHP file upload error
zighead


Joined: 26 Jun 2007
Posts: 1
Reply with quote
Can't seem to get file upload working using PHP. Would appreciate any help/advice.

This is the PHP code block:

Code:
<?

$uploadDir = '/vservers/designawards/htdocs/upload/';


if(isset($_POST['upload']))
{
   $fileName = $_FILES['userfile']['name'];
   $tmpName  = $_FILES['userfile']['tmp_name'];
   $fileSize = $_FILES['userfile']['size'];
   $fileType = $_FILES['userfile']['type'];

    $filePath = $uploadDir . $fileName;

    $result    = move_uploaded_file($tmpName, $filePath);
   if (!$result) {
      echo "Error uploading file";
      exit;
   }
   
    echo "<br>File uploaded<br>";
}      
?>


Have tried all sorts of upload directory paths with appropriate permissions set. The error for the case above, when uploadDir = /vservers/designawards/htdocs/upload/ is as follows:

Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/tmp/phpAgyZ6l) is not within the allowed path(s): (/vservers/designawards) in /vservers/designawards/htdocs/uploader_z.php on line 36

Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/tmp/phpAgyZ6l) is not within the allowed path(s): (/vservers/designawards) in /vservers/designawards/htdocs/uploader_z.php on line 36

Warning: move_uploaded_file(/tmp/phpAgyZ6l) [function.move-uploaded-file]: failed to open stream: Operation not permitted in /vservers/designawards/htdocs/uploader_z.php on line 36

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpAgyZ6l' to '/vservers/designawards/htdocs/upload/error.jpg' in /vservers/designawards/htdocs/uploader_z.php on line 36
Error uploading file


Please let me know how to fix this. Thanks in advance.
Permissions Errror
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 341
Reply with quote
Hello,
HMS is very strict about file permissions outside your home directory, and when php attempts to write a temporary file to /tmp, write permissions are denied. You may need to create a temporary directory within your own vserver. You can change the temporary upload dir in php.ini. I believe that the variable is upload_tmp_dir. If you already tried this, I am sorry if I could not help you. If this does not work, I would recommend contacting support.
nathacof


Joined: 24 Oct 2006
Posts: 93
Location: Bear, DE
Reply with quote

when php attempts to write a temporary file to /tmp, write permissions are denied. You may need to create a temporary directory within your own vserver. You can change the temporary upload dir in php.ini. I believe that the variable is upload_tmp_dir.


comprug is exactly right. The problem is the default behavior for customer's php.ini is to keep your scripts locked into the default base directory ie: /vservers/username/. As you can see /tmp is outside of that directory which is generating your errors.

You can set the upload_tmp_dir in your PHP script but I would recommend contacting support to update the php.ini to avoid this problem altogether.

To verify
Code:

-bash-3.00$ grep -e 'upload_tmp_dir' etc/php.ini
upload_tmp_dir = /vservers/username/tmp
-bash-3.00$
PHP file upload error
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic