Jessica Posted April 16, 2012 Share Posted April 16, 2012 I'm trying to copy an existing file using a php script, run on the command line. I've tried copy() and also a script from the comments on copy() http://www.php.net/manual/en/function.copy.php#102320 No matter how I try to open the file I get " failed to open stream: No such file or directory". I tried changing the name of the file, and the ext, and both. The file does exist, and if I run cp old new, the file gets copied fine. Current code <?php $source = '/www/documents/myfile.pdf'; $destination = '/www/documents/mypdf.pdf.bak'; copy($source, $destination); ?> Warning: copy(/www/documents/myfile.pdf): failed to open stream: No such file or directory in /www/cron/historic.php on line 3 ~$ ls /www/hua/compucom113dev/client/documents/ myfile.pdf ~$ cp /www/documents/myfile.pdf /www/documents/myfile.pdf.bak ~$ ls /www/hua/compucom113dev/client/documents/ myfile.pdf myfile.pdf.bak I had chmod in the script at one point to make sure the directory had the permissions needed but it didn't make a difference so I removed it. I can add it back if someone can help explain what to set it to. I was doing 0777 then back to 0755 at the end. Quote Link to comment https://forums.phpfreaks.com/topic/261034-failed-to-open-stream-no-such-file-or-directory/ Share on other sites More sharing options...
Muddy_Funster Posted April 16, 2012 Share Posted April 16, 2012 All I can think of is checking the availability of each directory, as running from shell could have a different root than running from a web script $dir1 = '/'; $files1 = scandir($dir1); var_dump($files1); $dir2 = '/www'; $files2 = scandir($dir2); var_dump($files2); $dir3 = '/www/documents'; $files3 = scandir($dir3); var_dump($files3); probably something you've done already, but it's all I got, sorry. Quote Link to comment https://forums.phpfreaks.com/topic/261034-failed-to-open-stream-no-such-file-or-directory/#findComment-1337806 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.