-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 .

user181452
  • 123
  • 1
  • 1
  • 4
  • Check [here](http://serverfault.com/questions/364677/why-is-chmod-r-777-destructive) and [here](http://stopdisablingselinux.com/). 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
  • but it's a bad practice , do you suggest an alternative way ? – user181452 Jul 20 '13 at 11:34
  • 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

2 Answers2

1

Your permissions on the /tmp share is incorrect.

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

pauska
  • 19,620
  • 5
  • 57
  • 75
0

You got the error "Failed to open stream: access denied". What to do?

  1. Find out the php error code. Place this code at the beginning of your php.
    ini_set ('error_reporting', E_ALL); ini_set ('display_errors', 1); ini_set ('display_startup_errors', 1);
  1. The folder must be accessible 777. Check it.
  2. The tag must have the enctype = "multipart / form-data" method = "post" attribute.
    <form enctype = "multipart / form-data" method = "post">
  1. Fully open and view the $ _FILES array on the server.
    print_r ($ _FILES);
  1. Open and view the $ _FILES array on the client.
    file = document.getElementById ("get_avatar"). files [0]; parts = file.name.split ('.');
   var a = file.size; var b = parts.pop (); var c = file.type; alert (a + b + c);
  1. Check the rights of the user and user group to the directory.
    cd / var / www / your_site / user
    ls -l

More details: enter link description here

Lorem ipsum
  • 892
  • 5
  • 15
Alex V
  • 1