Re: [PHP] Getting a binary file from URL
On Sunday 22 April 2001 21:25, Sigitas Paulavicius wrote: Solution #1 $contents = fread ($pointer, 1); Solution #2 $contents=; while ($partial = fread ($pointer, 8192)) { $contents.=$partial; }; But test this before you rely on it. I once did this with (IIRC) PHP 4.0.1 and it read up to several hundred junk bytes after encountering EOF. -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) World domination. Fast. (Linus Torvalds about Linux) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Getting a binary file from URL
Hi, I'm trying to get a binary file from an URL and then save it to a local disk. I'm trying this: $fd = fopen ($filename, "rb"); $contents = fread ($fd, filesize ($filename)); fclose ($fd); $fp = fopen ($tempfile, "wb"); fwrite ($fp,$contents); fclose ($fp); If I use $filename="local_file" the script works great, but if I use $filename="http://myserver.com/remote_file" the resultant local file is empty. How can I do this? Thanks in advance, Jaime -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Getting a binary file from URL
Well, it use to happen... [from function.filesize.html] int filesize (string filename) This function will not work on remote files; the file to be examined must be accessible via the server's filesystem. Ok, I screwed up. But now that I know what went wrong, how can I override this? The docs said: "Fread() reads up to length bytes from the file pointer referenced by fp. Reading stops when length bytes have been read or EOF is reached, whichever comes first." How do I use fread to read until EOF? Note: I don't know the file size, it could be from 1 byte to xxx Mb. Thanks, Jaime -Mensaje original- De: Jaime Torres [mailto:[EMAIL PROTECTED]] Enviado el: domingo 22 de abril de 2001 12:07 Para: [EMAIL PROTECTED] Asunto: [PHP] Getting a binary file from URL Hi, I'm trying to get a binary file from an URL and then save it to a local disk. I'm trying this: $fd = fopen ($filename, "rb"); $contents = fread ($fd, filesize ($filename)); fclose ($fd); $fp = fopen ($tempfile, "wb"); fwrite ($fp,$contents); fclose ($fp); If I use $filename="local_file" the script works great, but if I use $filename="http://myserver.com/remote_file" the resultant local file is empty. How can I do this? Thanks in advance, Jaime -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Getting a binary file from URL
Solution #1 $contents = fread ($pointer, 1); Solution #2 $contents=""; while ($partial = fread ($pointer, 8192)) { $contents.=$partial; }; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]