Forum Moderators: coopster

Message Too Old, No Replies

error: unable to cache a remote file using copy

         

globay

2:06 pm on Dec 14, 2003 (gmt 0)

10+ Year Member



I used the following code to copy a remote file to my server:

copy($URL,$cachefile);

This worked very well on my old server, but it does not work on the new one.

I am getting the following error:

Unable to open 'http://[...]' for reading: No such file or directory in /local/copyfile.php on line 23

I searched for more than two hours, but I have not found the solution.

On the php.net I found the following:

Note: As of PHP 4.3.0, both source and dest may be URLs if the "fopen wrappers" have been enabled.

I am using PHP 4.2., though I don't think that this is the reason, why it does not work.

Thanks in advance,

--
globay

Robert Thivierge

2:29 pm on Dec 14, 2003 (gmt 0)

10+ Year Member



Does your php.ini file have the following entry?

allow_url_fopen = On

globay

3:06 pm on Dec 14, 2003 (gmt 0)

10+ Year Member



yes, it does

<added>
it says:
Directive - Local Value - Master Value
allow_url_fopen - 1 - 1
</added>

coopster

8:53 pm on Dec 14, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you made sure the directory exists that you are trying to copy to and also that the permissions are set correctly?

globay

10:02 pm on Dec 14, 2003 (gmt 0)

10+ Year Member



Yes, the cache folder exists and all parent folders are set to 0777.

I think, the error might be in opening the file, that I want to copy:

Unable to OPEN [...]

Also it is very strange, that PHP thinks that the file is supposted to be in the same folder as folder as the php-file with the copy function. It should look for the file at the remote host [http://...]

--
globay

Robert Thivierge

1:03 pm on Dec 15, 2003 (gmt 0)

10+ Year Member



Does fopen() work with the url?

globay

2:37 pm on Dec 15, 2003 (gmt 0)

10+ Year Member



Yes, fopen works. On an other forum, somebody mentioned, that copy() is not able to open remote files if you are using a PHP version lower to 4.3, which is my case.

Now I am using this code, which for unknown reasons ends up in an infinite loop, once in a while.

$fi=fopen($URL,"r");
$fl=fopen($cachefile,"w");
while(!feof($fi)){
fwrite($fl,fread($fi,20000));
}
fclose($fl);
fclose($fi);

Does anybody have an idea why?

coopster

3:11 pm on Dec 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There is a warning in the manual regarding this issue:
When reading from network streams or pipes, such as those returned when reading remote files or from popen() and proc_open(), reading will stop after a packet is available. This means that you should collect the data together in chunks...

See the fread [php.net] function pages for more information.

Also, this thread regarding Help with fread() - Limit size of file being read? [webmasterworld.com] may offer some insight...