dsj83686 2012-03-06 16:27
浏览 54
已采纳

PHP move_uploaded_file无法在公共服务器上运行

I am trying to upload my php project into public server. I made the image upload file when I create product or edit product. It works in localhost, but when I move to public server, it is not working. I think move_uploaded_file part does not working. How can I change the link? or do I have to change anything? When I see Filzilla, I can see remote site that it is '/www/eshopProject/inventory_images'. And index file is '/www/eshopProject/storeAdmin'. Do I have to change link like this? I don't know how can I change the link. Could you help me? uploading the image into public server is not working.. Is it any security issue? or something? Please help me. Thanks.

--index.php--

$pid = mysql_insert_id();
//Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/product_$newname");
  • 写回答

3条回答 默认 最新

  • dongse5408 2012-03-06 17:40
    关注

    First of all check the permissions of the directory as mentioned in come of the comments. If you have shell access "chmod 777 target_dir" or "chmod 707 target_dir" should be sufficient.

    Second try to debug it using if's and the file_exists function(http://php.net/manual/en/function.file-exists.php).

    Something like this.

    $uploadedFile = $_FILES['fileField']['tmp_name'];
    $destination = "../inventory_images/product_$newname";
    
    if(file_exists($uploadedFile))
    {
       echo "file uploaded to temp dir";
    }
    else
    {
       echo "file upload failed";
       exit();
    }
    
    if(move_uploaded_file($uploadedFile, $destination))
    {
       echo "upload complete";
    }
    else
    {
       echo "move_uploaded_file failed";
       exit();
    }
    

    You can also check your current working directory by using the FILE or DIR constants(http://php.net/manual/en/language.constants.predefined.php).

    Try this.

    echo __FILE__;
    echo dirname(__FILE__);
    echo __DIR__;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿