[function.copy]: failed to open stream: No such file or directory | Newbie | | Join Date: Feb 2009
Posts: 23
| |
"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: - <?php
-
$handle = @fopen("url.txt", "r");
-
if ($handle)
-
{
-
while (!feof($handle))
-
{
-
$buffer = fgets($handle, 4096);
-
$filename=basename($buffer);
-
copy($buffer,$filename);
-
}
-
fclose($handle);
-
}
-
?>
-
url.txt content: - http://googlea4.com/download/software/internet/Yahoo!_Messenger_Vista_10/GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg
-
http://www.googlea4.com/GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar
-
www.googlea4.com/mehr4/magazine/mehr4-booltan5-web.pdf
-
sefidshahr.googlea4.com/yadegari/Y1.pdf
-
Error: - 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
-
-
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
-
-
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
-
_______________________________________________
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | 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
| | | re: [function.copy]: failed to open stream: No such file or directory
i change my url: -
http://www.googlea4.com/download/software/internet/Yahoo!_Messenger_Vista_10/GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg
-
http://www.googlea4.com/GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar
-
http://www.googlea4.com/mehr4/magazine/mehr4-booltan5-web.pdf
-
http://sefidshahr.googlea4.com/yadegari/Y1.pdf
-
but: -
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
-
-
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
-
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | 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
| | | re: [function.copy]: failed to open stream: No such file or directory
yes now you can download it!
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | re: [function.copy]: failed to open stream: No such file or directory Quote:
Originally Posted by ghasembaghi yes now you can download it! I'm sorry, does that mean your copy() is now working?
| | Newbie | | Join Date: Feb 2009
Posts: 23
| | | re: [function.copy]: failed to open stream: No such file or directory
i change the code: -
<?php
-
$_handle = @fopen("url.txt", "r");
-
if ($_handle)
-
{
-
while (!feof($_handle))
-
{
-
$_buffer = fgets($_handle, 4096);
-
$_filename = basename($_buffer);
-
if (copy($_buffer,$_filename))
-
{
-
echo "true : ";
-
echo $_filename;
-
echo "<br>";
-
}
-
}
-
fclose($_handle);
-
}
-
?>
-
and the output: -
true : GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg
-
true : GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar
-
true : mehr4-booltan5-web.pdf
-
true : Y1.pdf
-
but only "Y1.pdf" copied and other files not copied!
i change link order (change "Y1.pdf" and "mehr4-booltan5-web.pdf"): -
http://googlea4.com/download/software/internet/Yahoo!_Messenger_Vista_10/GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg
-
http://googlea4.com/GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar
-
http://sefidshahr.googlea4.com/yadegari/Y1.pdf
-
http://googlea4.com/mehr4/magazine/mehr4-booltan5-web.pdf
-
in this order only "mehr4-booltan5-web.pdf" copied and other files not copied!
and return this output: -
true : GoogleA4.com_Yahoo!_Messenger_Vista_interface.jpg
-
true : GoogleA4.com_Portable_Google_Chrome_2.0.156.1.rar
-
-
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
-
true : mehr4-booltan5-web.pdf
-
| | Newbie | | Join Date: Feb 2009
Posts: 23
| | | re: [function.copy]: failed to open stream: No such file or directory Quote:
Originally Posted by Markus 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
| | | re: [function.copy]: failed to open stream: No such file or directory
please help me.
please help me.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | 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?
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | 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
| | | 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!
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | re: [function.copy]: failed to open stream: No such file or directory Quote:
Originally Posted by ghasembaghi
thanks
thanks
thanks
thanks
you are very clever! You're very welcome.
- Markus.
| | Newbie | | Join Date: Feb 2009
Posts: 23
| | | 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?
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | 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.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,501 network members.
|