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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度