I am working on php web application where i upload a file on server from local machine using following code.
<form action="upload.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="fileToUpload" id="fileToUpload" value="c:/passwords.txt">
<input type="submit" value="Upload" name="submit">
</form>
upload.php
$target_dir = "uploads/";
$target_file = $target_dir .basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
if ($_FILES["fileToUpload"]["size"] > 5000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
echo $_FILES['fileToUpload']['name']."<br>";
if(move_uploaded_file($_FILES["fileToUpload"]["name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
But above code is not working. I checked uploads folder permission
drwxrwxrwx 2 ankit ankit 4096 Aug 2 13:41 uploads
which seems to be writable. I changed my project permission using following command
sudo chmod -R 777 /var/www/myproject
But still i cannot upload the files on server. May i know where i am wrong?