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/

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation