davehardyuk Posted March 7, 2006 Share Posted March 7, 2006 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted March 7, 2006 Share Posted March 7, 2006 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--]; Quote Link to comment Share on other sites More sharing options...
davehardyuk Posted March 7, 2006 Author Share Posted March 7, 2006 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 27The 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 Quote Link to comment Share on other sites More sharing options...
davehardyuk Posted March 7, 2006 Author Share Posted March 7, 2006 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 Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted March 7, 2006 Share Posted March 7, 2006 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.