doulongti5932 2014-12-14 23:11
浏览 45
已采纳

PHP将文件从一个目录复制到另一个目录会引发错误

I have two directories I am using, where I want to make a copy of the file in a different directory.

$dest = "/home/********/public_html/$userUName/SharedFiles/";
            $source = "/home/********/public_html/$username/$value";
            if(file_exists($dest))
            {
                //echo $source;
                //echo $dest;
                copy($source, $dest);
            }

$source and $dest are definitely getting the right values required, but it's throwing an error

Warning: copy(/home/********/public_html/johnny/SharedFiles/) [function.copy]: failed to open stream: Is a directory in /home/********/public_html/MainHomescreen.php on line 380

which is the copy line.

Have been through many options to fix it by googling. Have checked file permissions, as far as I can see I've got everything in the right place, so have come to a dead end of where I've gone wrong!

  • 写回答

1条回答 默认 最新

  • dongwei1954 2014-12-14 23:23
    关注

    PHP copy function is used to copy Files not Directories. Your destination is a Directory, because it ends with '/' .

    To solve your problem, you must also add the file name to be created:

    $dest = "/home/********/public_html/$userUName/SharedFiles/SomeNewFile.txt";

    This is also true for the source.

    Good luck,

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

报告相同问题?

悬赏问题

  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误