Jump to content

Archived

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

davehardyuk

Copy command not working

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

Share this post


Link to post
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--];

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sorted it now!

Needed \\$file for some reason.

Although i now need it to copy index.php and overite any existing index.php file, but only if it exists, otherwise just copy it.
Any ideas how to do this?

Thanks,

Dave

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

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.