Jump to content


Photo

Copy command not working


  • Please log in to reply
4 replies to this topic

#1 davehardyuk

davehardyuk
  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationPlymouth, UK

Posted 07 March 2006 - 12:48 PM

Hi Guys,

I have this code:

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

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



#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 March 2006 - 12:55 PM

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--];
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 davehardyuk

davehardyuk
  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationPlymouth, UK

Posted 07 March 2006 - 12:59 PM

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

#4 davehardyuk

davehardyuk
  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationPlymouth, UK

Posted 07 March 2006 - 01:34 PM

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


#5 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 07 March 2006 - 04:32 PM

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

<?php

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

?>

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

Happy coding!

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users