Jump to content

failed to open stream: No such file or directory


Jessica

Recommended Posts

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.

Link to comment
Share on other sites

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.

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.