Jump to content

Copy command not working


davehardyuk

Recommended Posts

Hi Guys,

I have this code:

[code]$source_file = 'copy/index.php';
$dest_file = 'F:\iTunes\$file\index.php';
copy($source_file, $dest_file); [/code]

I want it to copy index.php to a location that includes a variable ($file) that holds a folder name but it doesn't seem to like it.

Any ideas?

Thanks in advance!

Dave

Link to comment
https://forums.phpfreaks.com/topic/4323-copy-command-not-working/
Share on other sites

You need double quotes to expand variables's value

$dest_file = [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][!--sizeo:4--][span style=\"font-size:14pt;line-height:100%\"][!--/sizeo--]"[!--sizec--][/span][!--/sizec--][!--colorc--][/span][!--/colorc--]F:\iTunes\$file\index.php[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][!--sizeo:4--][span style=\"font-size:14pt;line-height:100%\"][!--/sizeo--]"[!--sizec--][/span][!--/sizec--][!--colorc--][/span][!--/colorc--];
Just tried that but comes up with the same error.

Here's what it gives me:

Warning: copy(F:\iTunes$file\index.php) [function.copy]: failed to open stream: No such file or directory in c:\Inetpub\wwwroot\list.php on line 27

The wwwroot has read/write for any user.

I know that $file is holding the folder as it's being printed out on the same page!

Also for some reason it's taking out the backslash before the variable which i presume is why it's not working!

Thanks alot,

Dave
because \$ is the escape for a $ rather than print a variable it prints the $ followed by the variable name. the simple solution is:

[code]
<?php

$source_file = 'copy/index.php';
$dest_file = 'F:\iTunes\'.$file.'\index.php';
copy($source_file, $dest_file) or die("Failed!");
echo "Success!";

?>
[/code]

Provided the server can access (F:) to write the file everything should work fine now.

Happy coding!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.