无法在Amazon EC2上上传文件-PHP [英] Unable to upload files on Amazon EC2 - php

查看:92
本文介绍了无法在Amazon EC2上上传文件-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在我的Amazon EC2实例上上传文件.文件上传不起作用.即使在error_reporting(E_ALL)之后,我也没有收到任何错误;没有通知或警告出现.我在不同的服务器(ipage)上使用了相同的代码,并且该代码有效.我在另一个亚马逊上的另一个bitnami实例上尝试了它,但它也不能正常工作.我猜测问题是在实例上写入文件的权限.因此,我寻求有关如何更改权限或暗示代码中可能出现错误的可能性的帮助.

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>

推荐答案

由于权限问题.只需将您的upload_files/目录的权限更改为644.它将正常运行.

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

这篇关于无法在Amazon EC2上上传文件-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆