I'm trying to run this code to copy file(s) from one server to another:
<?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 />';
}
?>
Here is the error I'm getting:
COPY ERROR: 2
copy(/sxlsv-leapwebdv/c$/inetpub/wwwroot/leap/Deleteme.txt): failed to open stream: No such file or directory
The file DOES exist - when I navigate to that same path in Windows Explorer, I can access that directory and file.
Am I doing something wrong?
You have to escape your backslashes. Well okay, you're using single quotes, so you're mostly good. But '\\\\'
evaluates to a single backslash, to make escaping a single quote (via '\\''
) possible. So you need to change your paths to
$from = '\\\\sxlsv-leapwebdv\\c$\\inetpub\\wwwroot\\leap\\Deleteme.txt';
$to = '\\\\sxlsv-leapwebqa\\c$\\inetpub\\wwwroot\\leap\\Deleteme.txt';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.