Connecting Tech Pros Worldwide Forums | Help | Site Map

[function.copy]: failed to open stream: No such file or directory

Newbie
 
Join Date: Feb 2009
Posts: 23
#1: Feb 16 '09
"copy.php" script want to copy all files(url in "url.txt" file) to this server, but return "error"!
Please help me.
note: i use copy function for copy file from another server (single file) in other script without any problem.

copy.php content:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $handle = @fopen("url.txt", "r");
  3. if ($handle)
  4.     {
  5.     while (!feof($handle))
  6.         {
  7.         $buffer = fgets($handle, 4096);
  8.         $filename=basename($buffer);
  9.         copy($buffer,$filename);
  10.         }
  11.     fclose($handle);
  12.     }
  13. ?>
  14.  
url.txt content:
Expand|Select|Wrap|Line Numbers
  1. http://googlea4.com/download/software/internet/Yahoo!_Messenger_Vista_10/GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg
  2. http://www.googlea4.com/GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar
  3. www.googlea4.com/mehr4/magazine/mehr4-booltan5-web.pdf
  4. sefidshahr.googlea4.com/yadegari/Y1.pdf
  5.  
Error:
Expand|Select|Wrap|Line Numbers
  1. Warning: copy(www.googlea4.com/mehr4/magazine/mehr4-booltan5-web.pdf ) [function.copy]: failed to open stream: No such file or directory in /home/fhlinux193/b/domain.com/user/htdocs/copy.php on line 9
  2.  
  3. Warning: copy(sefidshahr.googlea4.com/yadegari/Y1.pdf ) [function.copy]: failed to open stream: No such file or directory in /home/fhlinux193/b/domain.com/user/htdocs/copy.php on line 9
  4.  
  5. Warning: copy( ) [function.copy]: failed to open stream: No such file or directory in /home/fhlinux193/b/domain.com/user/htdocs/copy.php on line 9
  6.  
_______________________________________________

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Feb 16 '09

re: [function.copy]: failed to open stream: No such file or directory


Judging by the first 2 urls, you're giving an absolute path to each file. However, when you omit the 'http(s)://' from the url, it will be treated as a relative file. That is to say, PHP is looking for the file under your htdocs directory.

Change your links to absolute links, and I think it may work fine.
Newbie
 
Join Date: Feb 2009
Posts: 23
#3: Feb 16 '09

re: [function.copy]: failed to open stream: No such file or directory


i change my url:
Expand|Select|Wrap|Line Numbers
  1. http://www.googlea4.com/download/software/internet/Yahoo!_Messenger_Vista_10/GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg
  2. http://www.googlea4.com/GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar
  3. http://www.googlea4.com/mehr4/magazine/mehr4-booltan5-web.pdf
  4. http://sefidshahr.googlea4.com/yadegari/Y1.pdf
  5.  
but:
Expand|Select|Wrap|Line Numbers
  1. Warning: copy(http://sefidshahr.googlea4.com/yadegari/Y1.pdf ) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/fhlinux193/b/domain.com/user/htdocs/copy.php on line 9
  2.  
  3. Warning: copy( ) [function.copy]: failed to open stream: No such file or directory in /home/fhlinux193/b/domain.com/user/htdocs/copy.php on line 9
  4.  
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#4: Feb 16 '09

re: [function.copy]: failed to open stream: No such file or directory


Can you confirm that the file 'http://sefidshahr.googlea4.com/yadegari/Y1.pdf' exists?
Newbie
 
Join Date: Feb 2009
Posts: 23
#5: Feb 16 '09

re: [function.copy]: failed to open stream: No such file or directory


yes now you can download it!
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#6: Feb 16 '09

re: [function.copy]: failed to open stream: No such file or directory


Quote:

Originally Posted by ghasembaghi View Post

yes now you can download it!

I'm sorry, does that mean your copy() is now working?
Newbie
 
Join Date: Feb 2009
Posts: 23
#7: Feb 16 '09

re: [function.copy]: failed to open stream: No such file or directory


i change the code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $_handle = @fopen("url.txt", "r");
  3. if ($_handle)
  4.     {
  5.     while (!feof($_handle))
  6.         {
  7.         $_buffer = fgets($_handle, 4096);
  8.         $_filename = basename($_buffer);
  9.         if (copy($_buffer,$_filename))
  10.         {
  11.             echo "true : ";
  12.             echo $_filename;
  13.             echo "<br>";
  14.         }
  15.         }
  16.     fclose($_handle);
  17.     }
  18. ?>
  19.  
and the output:
Expand|Select|Wrap|Line Numbers
  1. true : GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg 
  2. true : GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar 
  3. true : mehr4-booltan5-web.pdf 
  4. true : Y1.pdf
  5.  
but only "Y1.pdf" copied and other files not copied!
i change link order (change "Y1.pdf" and "mehr4-booltan5-web.pdf"):
Expand|Select|Wrap|Line Numbers
  1. http://googlea4.com/download/software/internet/Yahoo!_Messenger_Vista_10/GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg
  2. http://googlea4.com/GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar
  3. http://sefidshahr.googlea4.com/yadegari/Y1.pdf
  4. http://googlea4.com/mehr4/magazine/mehr4-booltan5-web.pdf
  5.  
in this order only "mehr4-booltan5-web.pdf" copied and other files not copied!
and return this output:
Expand|Select|Wrap|Line Numbers
  1. true : GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg 
  2. true : GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar 
  3.  
  4. Warning: copy(http://sefidshahr.googlea4.com/yadegari/Y1.pdf ) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/fhlinux193/b/backup.linkpress.ir/user/htdocs/copy.php on line 9
  5. true : mehr4-booltan5-web.pdf
  6.  
Newbie
 
Join Date: Feb 2009
Posts: 23
#8: Feb 16 '09

re: [function.copy]: failed to open stream: No such file or directory


Quote:

Originally Posted by Markus View Post

I'm sorry, does that mean your copy() is now working?

no!
that mean this file exists in sefidshahr.googlea4.com
Newbie
 
Join Date: Feb 2009
Posts: 23
#9: Feb 17 '09

re: [function.copy]: failed to open stream: No such file or directory


please help me.
please help me.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#10: Feb 17 '09

re: [function.copy]: failed to open stream: No such file or directory


I'm not sure of the problem.. but I have noticed Y1.pdf takes a long time to load; maybe that's causing the error?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#11: Feb 17 '09

re: [function.copy]: failed to open stream: No such file or directory


Ok, after nearly 30 minutes of tearing my hair out*, I think I've solved the issue. I'm not sure why, but when you pull the values out of the text file, a space is being added to the end of the value - this happens to every line, apart from the last line. This is why whatever url was on the last line was being copied correctly.

The fix: use trim() on your $buffer variable.

http://uk2.php.net/trim

* I love my hair, you had better appreciate this!
Newbie
 
Join Date: Feb 2009
Posts: 23
#12: Feb 17 '09

re: [function.copy]: failed to open stream: No such file or directory



thanks
thanks
thanks
thanks
you are very clever!
this script is my first script in php, you stay in mind for always!
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#13: Feb 17 '09

re: [function.copy]: failed to open stream: No such file or directory


Quote:

Originally Posted by ghasembaghi View Post


thanks
thanks
thanks
thanks
you are very clever!

You're very welcome.

- Markus.
Newbie
 
Join Date: Feb 2009
Posts: 23
#14: Feb 17 '09

re: [function.copy]: failed to open stream: No such file or directory


one question:
when i transfer huge files with this script (upper mega) some error maybe happen:
1- Fatal error: Maximum execution time of 300 seconds exceeded.
2- 500 internal server error
3- time out
can any way prevent this problem (by php script. no by php server settings).
for example when file1's copy started, this operation continued with server and script go to next files's copy.
any script suggestion?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#15: Feb 17 '09

re: [function.copy]: failed to open stream: No such file or directory


If you set max_execution_time(0), you script won't time out. Not sure about the 500 error though.
Reply


Similar PHP bytes