-1
I have the following html and php code running on my server, however, whenever I try to upload a file, I get the message "There was an error uploading the file, Please Try Again!" and I can’t understand why...
<!DOCTYPE html>
<html>
<head>
<title>Upload your files</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p>Upload your file</p>
<input type="file" name="uploaded_file"></input><br />
<input type="submit" value="Upload"></input>
</form>
</body>
</html>
<?PHP
if(!empty($_FILES['uploaded_file']))
{
$path = "uploads/";
$path = $path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['uploaded_file']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>
My server is Apache/2.4.25 (Debian).
I wonder if you can help me?
Apparently your problem is in setting the $path variable. Is this uploads directory on the same level as the upload.php file? Provisionally places error_reporting( E_ALL); at the beginning of the upload.php file to have exact notion of the error generated by move_uploaded_file.
– Benilson
Here is an example ready.
– Ivan Ferrer
@Benilson yes uploads directory is at the same level as upload.php. I put error_reporting( E_ALL); and I was returned the number 22527...
– Filipe Martins
@Ivanferrer tried with this example and returned the message "Error sending"...
– Filipe Martins
Your error, is when it tries to call move_uploaded_file, for some reason it is not allowed to move from the temporary folder to the upload directory, maybe the problem is in the upload folder that must be without write permission, try writing the folder:
chmod(realpath(dirname(__FILE__) . "/upload/"), 0755)
, or something like that...– Ivan Ferrer
Barter
$path = "uploads/";
for$path = __DIR__ . "/uploads/";
– Benilson