PHP upload problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nikosb
Forum Newbie
Posts: 8
Joined: Sat Sep 23, 2006 5:46 pm

PHP upload problem

Post by nikosb »

I have a strange PHP problem when I try to upload an image.
I have a Unix Solaris server with multiple user accounts. I have a basic a html code

Code: Select all

<HTML>
  <BODY>

    <form enctype="multipart/form-data" action="testupload.php" method="POST">

      <input type="hidden" Name="MAX_FILE_SIZE" value="300000" />
      <input name="imgfile" Type="file" size="28" />&nbsp;&nbsp;
      <input type="SUBMIT" value="Upload" class="h11" />
  </form>
</BODY>

</HTML>
The testupload.php looks like this

Code: Select all

<?php
print_r($_FILES);
?>
When I test this script from one user account (corresponding to /home/user1/www/upload.html) the script works and files are uploaded to a temporary directory.

When I test the same script from the other user account (corresponding to /home/user2/www/upload.html) the script does not work. I get the following output

Code: Select all

Array
(
    [imgfile] => Array
        (
            [name] => winampmb.htm
            [type] => 
            [tmp_name] => 
            [error] => 6
            [size] => 0
        )

)
The error number 6 means that the upload directory is not defined. Why is this happening for user2 and not for user1 since both users are on the same server running the same version of php with the same user permissions?
I read through the php manual and there it explains that if the tmp upload directory is not defined in php.ini then php uses the default system directory. To make sure that there is a default system php dir I run the script from user1 and I find out that [imgfile][name] = /tmp/tmpname which means that the system temp upload directory is defined as /tmp. I also checked the permission of /tmp and they are drwxrwxrwt which I means that everybody should have write access to it, both "user1" and "user2" and "nobody"
I have spent a lot of time into this but I could not figure out a way to make the php upload work for user2. Can anybody give me some advice on what to look next? Is this possibly a PHP bug?

Thank you in advance,

Nikolaos
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP upload problem

Post by Christopher »

It sounds like a permissions problem. The web server may not even have access to one of the parents of the target upload directory. Make sure the permissions are correct or create a directory somewhere where you can.
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP upload problem

Post by Benjamin »

This could be an SE Linux issue.

http://www.nsa.gov/selinux/
Post Reply