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

2 Answers2

1

Your permissions on the /tmp share is incorrect.

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

pauska
  • 19,766
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

Alex V
  • 1