-3

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 .

  • Check here and here. I hope this is a development machine, and not something somebody's business depends on. – dawud Jul 20 '13 at 11:10
  • of course it's a development server ! and if you hit "failed to open stream: Permission denied" on google search , you'll find that all search results would give you what I have written ! – user181452 Jul 20 '13 at 11:15
  • what are the permissions on /home/safaa? (ls -lrtd /home/safaa) – dawud Jul 20 '13 at 11:24
  • it's drwx------. 8 safaa safaa 4096 Jul 17 15:17 /home/safaa – user181452 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

Your permissions on the /tmp share is incorrect.

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

  • thanks , changing /home/safaa permission solved the problem – user181452 Jul 20 '13 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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