Enable permissions on a folder to allow file upload.
You need to run the command
chmod -Rf 777 FOLDER_PATH
here FOLDER_PATH is the your folder path where the images get stored
Comments
-
Jamie Fearon about 4 years
I'm using xampp on a mac. I have the following script which I'm trying to use to upload a file to a folder:
upload.php
<?php $allowedExts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $_FILES["file"]["name"])); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 20000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?>
The upload form is simply:
index.html
<html> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file"><br> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
My folder structure in htdocs is:
-/htdocs -index.html -upload.php -/upload
When I run the script I get the following error:
Warning: move_uploaded_file(upload/dirt.png) [function.move-uploaded-file]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/development/Templates/PHP&JS/Upload Files to Server/form upload/upload.php on line 29
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpAQWDB1' to 'upload/dirt.png' in /Applications/XAMPP/xamppfiles/htdocs/development/Templates/PHP&JS/Upload Files to Server/form upload/upload.php on line 29 Stored in: upload/dirt.png
How do I change the properties of the upload folder to allow uploading of files? I there a config file I should include to enable this?