uploading image file using php in ubuntu or linux not working

PHP script might be prevented form uploading file because of permissions : Ubuntu/Linux

Am having this php script that should upload image

save it as upload.html

<!DOCTYPE html><html>
<head>
<title>UPLOAD</title>

</head>
<body>
<form method=”post” action=”upload.php” enctype=”multipart/form-data”>
<pre>
Select File<input type=”file” name=”file”>

<input type=”submit” name=”btn” value=”UPLOAD”>
</pre>
</form>

</body>
</html>

save as upload.php

<?php
$file_name=$_FILES[“file”][“name”];
$temp_name=$_FILES[“file”][“tmp_name”];
if(move_uploaded_file($temp_name,”/var/www/”.$file_name))
echo “File Uploaded”;
else
echo “file can’t be uploaded”;
?>

now when you will try to upload image image will not be uploaded as because of  file permission
so to solve
Fixing file permissions for the entire www directory: 
open terminal and either copy paste or type it
sudo chown -R www-data:www-data /var/www/

Leave a Comment

Your email address will not be published. Required fields are marked *

To Resolve this issue at just 5$ from ServerExpert

https://serverexpert.io/

For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat