PHP从一个服务器复制文件到另一个服务器(得到一个错误)


PHP Copy File(s) From One Server to Another (getting an error)

我试图运行这段代码将文件从一个服务器复制到另一个服务器:

<?php
    $from = '''sxlsv-leapwebdv'c$'inetpub'wwwroot'leap'Deleteme.txt'; 
    $to = '''sxlsv-leapwebqa'c$'inetpub'wwwroot'leap'Deleteme.txt'; 
    if(!@copy($from,$to)) 
    { 
        $errors= error_get_last(); 
        echo "COPY ERROR: ".$errors['type']; 
        echo "<br />'n".$errors['message']; 
    } 
    else { 
        echo 'File copied from remote!<br />'; 
    } 
?>

下面是我得到的错误:

COPY ERROR: 2
copy(/sxlsv-leapwebdv/c$/inetpub/wwwroot/leap/Deleteme.txt): failed to open stream: No such file or directory

文件确实存在-当我在Windows资源管理器中导航到相同的路径时,我可以访问该目录和文件。

我做错了什么吗?

必须转义反斜杠。好吧,你用的是单引号,所以基本上没问题。但是''''计算为单个反斜杠,以使转义单个引号(通过'''')成为可能。所以你需要将路径改为

$from = '''''sxlsv-leapwebdv''c$''inetpub''wwwroot''leap''Deleteme.txt'; 
$to = '''''sxlsv-leapwebqa''c$''inetpub''wwwroot''leap''Deleteme.txt'; 
相关文章: