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
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--];
Link to comment
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
Link to comment
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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.