Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

uploading file to server is always giving me this error though I tried all solution on the web for this problem but I'm still getting this error no matter what :

Warning: move_uploaded_file(/home/safaa/uploads/d.txt): failed to open stream: Permission denied in /var/www/html/Administration/newEmptyPHP.php on line 47

Warning: move_uploaded_file(): Unable to move '/tmp/php6qK4Df' to '/home/safaa/uploads/d.txt' in /var/www/html/Administration/newEmptyPHP.php on line 47

Here's my HTML code :

     <form id="file_to_upload" name="file_to_upload" enctype="multipart/form-data" action="newEmptyPHP.php" method="post" >
            <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
            Browse for a root certificate to upload:
            <input type="file" name="uploaded_file">
             <input type="submit" value="Upload It Now" onclick="$('#file_to_upload').submit();">
    </form>

my PHP code :

 $file_name = $_FILES["uploaded_file"]["name"];

//User can upload only till 100kb file size.
    $file_tmp_name = $_FILES["uploaded_file"]["tmp_name"];
    $upload_path = "/home/safaa/uploads/" . $file_name;
//function for upload file
            if (move_uploaded_file($file_tmp_name, $upload_path)) {
                echo "Successful<BR>";
            }

I've tried these following solutions which they are all what I found on the web forums and stackoverflow questions and answers :

  1. Change permission of /tmp/ and /uploads/ to 777 and 0777 . "it didn't work"
  2. in php.ini , safe mode is off and file_uploads is on
  3. SELinux is Disabled :: getenforce gave me Disabled
 drwxrwxrwx.   6 nobody  root      4096 Jul 20 13:06 tmp

 drwxrwxrwx   2 nobody safaa  4096 Jul 17 15:17 uploads

neither of both worked .

share|improve this question
    
I seriously hope this server is not exposed to the Internet. –  dawud Jul 20 '13 at 10:44
    
if you don't want to answer don't show off by sarcastic comments with down votes !! –  user181452 Jul 20 '13 at 11:06
    
It is in no possible way sarcastic. Check here and here. Again, I hope this is a development machine, and not something somebody's business depends on. –  dawud Jul 20 '13 at 11:10
1  
Either way you've hosed up the permissions on the /tmp share, so you might as well fix it: chmod a+rwxt /tmp /var/tmp –  pauska Jul 20 '13 at 11:28
1  
Well, you should start re-enabling all the stuff you removed (safemode, SELinux), implement a firewall, make sure user accounts is secure etc. I don't know enough about PHP to verify if a code is proper or not. –  pauska Jul 20 '13 at 11:35

1 Answer 1

Your permissions on the /tmp share is incorrect.

Try the following: chmod a+rwxt /tmp /var/tmp

share|improve this answer
    
thanks , changing /home/safaa permission solved the problem –  user181452 Jul 20 '13 at 11:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.