dpzyd8865 2014-02-20 07:28
浏览 25
已采纳

php - 为什么move_uploaded_file不允许我将它存储到我的驱动器?

the below demo of code is suppose to store my image into a directory, however, using xammp i am confused on if i need permission to store it there as i am getting warnings and the file is not saving where i would like it to go.

<?php
//simple image check using getimagesize() instead of extensions
if($_FILES)
{
    $empty_check = getimagesize($_FILES['file']['tmp_name']);
    if(empty($empty_check))
    {
        echo 'this is not an image';
    }
    else
    {
        echo 'you have uploaded ' . explode('.',$_FILES['file']['name'])[0].' and it is a ' . explode('.',$_FILES['file']['name'])[1].'.';
        //an example of how i would extract the extension
        $target = "C:\xampp\tmp";
        move_uploaded_file($_FILES['file']['tmp_name'], $target);
    }
}
?>
  • 写回答

3条回答 默认 最新

  • dounao1875 2014-02-20 07:33
    关注

    Escape the backslashes in your path!:

    $target = "C:\xampp\tmp";
    //should be
    $target = "C:\\xampp\\tmp";
    

    Considering \t is interpreted as a tab, your path reads like this:

    $target = "C:[?]ampp    mp";
    

    But really, you can just use the forward slashes:

    $target = '/xampp/tmp';
    

    If this still doesn't work, make sure you have write-rights on that directory, and fix that if necessary

    Then, finally read the docs:

    move_uploaded_file($_FILES['file']['tmp_name'], $target.'/filename_here.ext');
    

    You have to add the file name to the target argument!

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

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line