简体   繁体   中英

Unable to upload files on Amazon EC2 - php

I am using the following code to upload files on my Amazon EC2 instance. The file upload does not work. I don't get any error even after error_reporting(E_ALL); no notices or warnings come up. I used the same code on different server (ipage) and the code works. I tried it on another bitnami instance on different amazon and it does not work on that as well. I am guessing the problem is permissions to write file on the instances. I thus ask for help on either how to change the permissions or hinting some possibilities of error that might be in the code.

<?php 
error_reporting(E_ALL);
{
        $pic = $_FILES['pic']['name'];
        $pic_loc = $_FILES['pic']['tmp_name'];
        $folder="uploaded_files/";
        if(move_uploaded_file($pic_loc,$folder.$pic))
        {
            ?><script>alert('successfully uploaded');</script><?php
        }
        else
        {
            ?><script>alert('error while uploading file');</script><?php
        } 
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>File Uploading With PHP and MySql</title>
  </head>
  <body>
    <form action="" method="post" enctype="multipart/form-data">
      <input type="file" name="pic" />
      <button type="submit" name="btn-upload">upload</button>
    </form>
  </body>
</html>

Its because of permission problem. Just change permission of your uploaded_files/ directory to 644. It will work correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM