douxi1738 2015-02-24 18:23
浏览 29
已采纳

尝试使用PHP上传文件?

I'm trying make a file upload using PHP. To do it I'm using $_FILE but I can't understand why does not works. Looking for solutions I'm found some suggestion to use $_FILE, but still can't do this works. To I see if upload works I'm using Postman of Chrome. I'm using Ubuntu with LAMP.

How could I do it ?

<?php

$arquivo = isset($_FILES["file"]) ? $_FILES["file"] : FALSE;

if(!$arquivo) { 
    echo "You can not access this file directly!"; 
}else{
    $diretorio = "/home/fernando/Imagens/";

    if (move_uploaded_file($arquivo["tmp_name"], $diretorio.$arquivo["name"])) { 
            echo "File upload ok!"; 
    }else{
         echo "File not upload!"; 
    }   
}

?>

Exception

<br />
<b>Warning</b>:  move_uploaded_file(/home/fernando/Imagens/avatar_empresa.jpg): failed to open stream: Permission denied in 
<b>/var/www/TelefonesUteis/ws/add_file.php</b> on line 
<b>12</b>
<br />
<br />
<b>Warning</b>:  move_uploaded_file(): Unable to move '/tmp/phpq9AlVw' to '/home/fernando/Imagens/avatar_empresa.jpg' in 
<b>/var/www/TelefonesUteis/ws/add_file.php</b> on line 
<b>12</b>
<br />

Postman

enter image description here

  • 写回答

1条回答 默认 最新

  • dongziche8030 2015-02-24 19:44
    关注

    Your script doesn't have permissions to add and/or execute files in /home/fernando/Imagens/. Your will have to use chmod:

    chmod -R 775 /home/fernando/Imagens

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog