Possible Duplicate:
Image uploading via PHP returning empty array
I am unable to successfully upload an image/file to my server. The php is as follows:
//This is the directory where images will be saved
$uploadDir = "./";
$uploadFile = $uploadDir . basename( $_FILES['photo']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $uploadFile)){
echo "The file has been uploaded successfully.";
} else {
print_r($_FILES);
}
I chose the directory at which this script lives, to ensure the functionality before I upload to the final directory. I want to upload photo’s, and will check for file extensions later – but for now I at least need the upload functionality to work.
The form is as follows:
<form id="imageUploadForm" name="imageForm" enctype="multipart/form-data" action="imageController.php" method="post">
<label for="photo" class="blogLabel">Upload an Image</label>
<input type="file" name="photo" id="imageUpload">
<input type="submit" name="submit" id="imageSubmit" class="btn btn-primary" value="Upload">
</form>
print_r($_FILES) returns: Array ( [photo] => Array ( [name] => imgres.jpeg [type] => image/jpeg [tmp_name] => /tmp/php1rqFUO [error] => 0 [size] => 15147 ) )
PHP doesn’t have permission to write to that directory. If you’re working on a LAMP stack, you need to give the world write access to that directory. From the commandline this is:
Be careful! You should actually use a different directory than the directory where your script lives. Choose a directory that cannot execute scripts so that someone doesn’t upload a script to your site then execute it with full access to your server!