dongxin1999 2016-04-16 21:00
浏览 30

无法在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>
  • 写回答

1条回答 默认 最新

  • duanguai2781 2018-03-10 06:36
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度