0
votes

i want to upload the file and save it to uploads folder in our directory. i have done that by using that code.. but its not working..here is an error..

"Warning: move_uploaded_file(uploads/1341221475::1aaaa.text): failed to open stream: Permission denied in /var/www/html/PHP/upload_file.php on line 24 Warning: move_uploaded_file(): Unable to move '/tmp/phpSZhm3c' to 'uploads/1341221475::1aaaa.text' in /var/www/html/PHP/upload_file.php on line 24 Stored in: aaaa/aaaa.text"

please help

code :

            if($_FILES["file"]["error"] > 0)
            {
                echo "ERROR ".$_FILES["file"]["error"]."<br>";
            }
            else
            {
                echo "NAME : ".$_FILES["file"]["name"]."<br>";
                echo "TYPE : ".$_FILES["file"]["type"]."<br>";
                echo "SIZE : ".($_FILES["file"]["size"]/1024)."KB<br>";
                echo "Stored in : ".$_FILES["file"]["tmp_name"]."<br>";
                if (file_exists("aaaa/" . $_FILES["file"]["name"]))
                      {
                    echo $_FILES["file"]["name"] . " already exists. ";
                      }
                else
                      {
                $target_path = "uploads/";
                    $target_path = $target_path . time() . $_SERVER['REMOTE_ADDR'] . basename( $_FILES['file']['name']);
                      move_uploaded_file($_FILES["file"]["tmp_name"],$target_path);
                      echo "Stored in: " . "aaaa/" . $_FILES["file"]["name"];
                      }
            }
4
Simply Give permissions to the folder !Bhavin Rana
If you're running linux chmod it. Its a simple permissions problemTarang

4 Answers

0
votes

Your web server is running under a certain user (for example, "www"). Make sure that user has write access to the uploads folder.

0
votes

Give permission to Apache (for example) as Owner of your output directory, it will then be able to create files.

0
votes

Whenever you write a file using code, the user that is running the code should have permission. In this case whoever started the apache webserver should have permission to write in that folder. Use chmod command to specify permissions.

In case you are not worried about security much, you can just provide 777 to the uploads folder like this. Assuming your uploads folder is in /var/www/html/site/uploads, then run

chmod -R 777 /var/www/html/site/uploads

HTH

0
votes

make sure your uploads folder has a full permission so that you can move your files into it.

try chmod 777 -R to the uploads directory. For example:

 $ sudo chmod 777 -R /var/www/html/PHP/uploads/