Help - Search - Member List - Calendar
Full Version: decompress remote file
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
roN @ work
Hi,

in my script i wanna download a gz file, decompress it and compare its
content to a string from my php-script. how would I do it? I tried:
$relayblacklist =
gzread("http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz", 10000);
if(stristr($relayblacklist,$relay)==false)
echo "no such entry!<br>n";
but I got: Warning: gzread(): supplied argument is not a valid stream
resource in /srv/www/htdocs/web2/html/php/nospam/pop.php on line 190

I think I first have download the file to a local one and then decompress
it. Is that right? How to download a binary file? I' just found file() but
how to handle this with binary?
Than you!
My server uses php 4.3.3

roN @ work
roN @ work wrote:
QUOTE
Hi,

in my script i wanna download a gz file, decompress it and compare its
content to a string from my php-script. how would I do it? I tried:
$relayblacklist =
gzread("http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz",
10000); if(stristr($relayblacklist,$relay)==false)
echo "no such entry!<br>n";
but I got: Warning: gzread(): supplied argument is not a valid stream
resource in /srv/www/htdocs/web2/html/php/nospam/pop.php on line 190

I think I first have download the file to a local one and then
decompress it. Is that right? How to download a binary file? I' just
found file() but how to handle this with binary?
Than you!
My server uses php 4.3.3

Also tried this:
CODE

$fp = fopen("http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz",
"rb");
$relayblacklist = gzread(fread ($fp,10000),10000);
fclose ($fp);
echo $relayblacklist;
unlink("http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz");

But:
[Output]
Warning: gzread(): supplied argument is not a valid stream resource in
/srv/www/htdocs/web2/html/php/nospam/pop.php on line 136

Warning: unlink(http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz): No
such file or directory in /srv/www/htdocs/web2/html/php/nospam/pop.php on
line 139
[/Output]

Hilarion
QUOTE
in my script i wanna download a gz file, decompress it and compare its
content to a string from my php-script. how would I do it? I tried:
$relayblacklist =
gzread("http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz",
10000); if(stristr($relayblacklist,$relay)==false)
echo "no such entry!<br>n";
but I got: Warning: gzread(): supplied argument is not a valid stream
resource in /srv/www/htdocs/web2/html/php/nospam/pop.php on line 190

I think I first have download the file to a local one and then
decompress it. Is that right? How to download a binary file? I' just
found file() but how to handle this with binary?

You need to pass stream resource from "gzopen" as first parameter
of "gzread", not path to the file.


QUOTE
Also tried this:
[Code]
$fp = fopen("http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz",
"rb");
$relayblacklist = gzread(fread ($fp,10000),10000);
fclose ($fp);

Same again. (This time you tried to pass zipped data to gzread instead
of handle given by "gzopen".)


QUOTE
echo $relayblacklist;
unlink("http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz");

You can't remove remote file. "Unlink" works only on local files.


It could be something like:

$gz = gzopen( "http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz", "r" );
$relayblacklist = gzread( $gz, 10000 );


but "gzopen" does not support HTTP (or FTP). It works only on local files.

There is a way to solve the problem (found in "gzopen" user notes on PHP
manual pages) using "fopen" and URL wrappers:

$fp = fopen( "compress.zlib://http://wget-mirrors.uceprotect.net/uce-pfsm-1/access.gz", "r" );
$relayblacklist = gzread( $fp, 10000 );


Hilarion

PS.: Read manuals. It's all there.


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.