Mengky Chen
Mengky Chen

Reputation: 63

Can't upload file using PHP on Ubuntu

I try a simple php upload file on Ubuntu, it not work. Even it work on Window

Here my html coded.

<form action="upload.php" method ="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" value="submit" name="submit"/>
</form>

Here my php coded.

<?php
  $name = $_FILES['file']['name'];
  $temp = $_FILES['file']['tmp_name'];

  if(move_uploaded_file($temp,"upload/".$name)){
   echo "Your file was uploaded";
}
 else
{ 
 echo "Your file cound't upload";
}

?>

Upvotes: 1

Views: 5910

Answers (4)

Nesar
Nesar

Reputation: 5644

In my case, I had to install php-xml extension.

sudo apt-get install php-xml

Worked perfectly after installing this extension.

The error I was getting

PHP Fatal error: Uncaught Error: Class "DOMDocument" not found in ../wp-content/plugins/svg-support/vendor/enshrined/svg-sanitize/src/Sanitizer.php:96 .... ../wp-content/plugins/svg-support/functions/attachment.php(246): bodhi_svgs_sanitize()\

Upvotes: 0

Samreach
Samreach

Reputation: 91

Change permission to UPLOAD file into upload folder on UBUNTU

Read + Write

sudo chmod -R a+rw upload/

Read + Write + Execute

sudo chmod -R a+rwx upload/

Upvotes: 5

Avinash Babu
Avinash Babu

Reputation: 6252

This can be done by giving the write permission to the directory in ubuntu..

You can see here on how to give write permissions..

https://superuser.com/questions/19318/how-can-i-give-write-access-of-a-folder-to-all-users-in-linux

Upvotes: 0

Mirza Arslan Baig
Mirza Arslan Baig

Reputation: 166

Check that you have given the write access to the "APACHE" on the directory.

Hope this will solve the problem.

Upvotes: 0

Related Questions