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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了