duanliang4009 2015-09-01 08:13
浏览 81
已采纳

PHP copy()无法打开流:无效的参数

I am trying to upload a file from my brower->PHP script->Server.

My browser and PHP script lie on the same server. I am using xampp on this. The server where I have to upload this file is different.

Here is my code:

$fdir = "http:\\\\myip\\D:\\errors\\";
$ffile = $fdir.basename($_FILES['myfile']['name']);
if (copy($ffile,$_FILES['myfile']['tmp_name'])) {
    echo "<br />"."File uploaded successfully";
} else {
    echo "<br />"."Error in uploading file";
}

I am getting the following error:

copy(http:\myip\D:\errors\IMG-20150424-WA0004.jpg): failed to open stream: Invalid argument in C:\xampp\htdocs\BS\myphp1.php on line 54

Any help would be appreciated.

EDIT:

I edited my code to remove http:// and use the name of the server. Also I am now using move_uploaded_file instead of copy

$fdir="\\\\TESTSRV\\D:\\errors\\";
$ffile=$fdir.basename($_FILES['myfile']['name']);
move_Uploaded_file($_FILES['myfile']['tmp_name'],$ffile);

But Still it gives me the error

move_uploaded_file(\TESTSRV\D:\errors\IMG-20150424-WA0004.jpg): failed to open stream: Invalid argument in C:\xampp\htdocs\BS\myphp1.php on line 54

  • 写回答

1条回答 默认 最新

  • dslkchyv673627 2015-09-01 08:26
    关注

    This is not the way to copy uploaded files - you need to use the function move_uploaded_file:

    if (move_uploaded_file($_FILES['myfile']['tmp_name'], "c:\\path\\to\\file")) {
        echo "<br />"."File uploaded successfully";
    } else {
        echo "<br />"."Error in uploading file";
    }
    

    Also I don't think your $fdir variable is a valid path in Windows. Basically the second argument of move_uploaded_file should be the target path, where you'd like to move the file.

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路