Forum Moderators: coopster
My first topic, and if can anyone help me I thanks very much.
The cenario:
I want read a webpage and then archive (save) the content in a file and show the content of file. I verify if the file is older or recent before save.
And the code I have:
function filecopy($urlsrc,$localdst) {
$fp_urlsrc = fopen($urlsrc,"r");
$del_File = fopen($localdst,"w");
fwrite($del_File,"");
fclose ($del_File);
while (!feof($fp_urlsrc)) {
$fp_localdst = fopen($localdst,"a");
fwrite ($fp_localdst, fread($fp_urlsrc, 1));
fclose ($fp_localdst);
}
fclose($fp_urlsrc);
}function archive(){
$source = "http://www.example.com/cgi-bin/por_cidade.pl?CIDADE=VISEU&imprimir=1";
$dest = "/home/ftp/incoming/web/public_html/Cinema/informa.cin";$fd = fopen("$source", "r" ) or die("<center>Unable to access source page</center>");
$pagina = fread($fd, 200000);
echo "pagina=$pagina";
fclose( $fd );if (file_exists($dest)) {
if (intval(date("Ymd", filectime($dest)))< intval(date("Ymd"))) { filecopy($source,$dest); }
} else {
filecopy($source,$dest);
}
}/*** CALL FUNCTION ***/
archive();
I receive this message:
Warning: file(http://www.example.com/cgi-bin/por_cidade.pl?CIDADE=VISEU&imprimir=1): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in "/home/ftp/incoming/web/public_html/Cinema/lercinema.php on line 133
Note: the file "informa.cin" have CHMOD 666.
Anyone can understand why I can "see" the webpage, but can read/save the content?!
Regards,
Bart
________
PS: Sorry my poor english :(
[edited by: jatar_k at 6:15 pm (utc) on Mar. 17, 2004]
[edit reason] no personal urls thanks [/edit]
Just an alternative, I think cURL is enabled by default with PHP, and you might find it useful, you can grab a URL and save it to file quite easily with CURL in around 10 lines of code.
[php.net...]
Thanks a lot -brotherhood of LAN-, great tip.
I test and I can get the webpage without problem :D
Thanks again.
I post here a function to load the webpage:
(...)function GetCurlPage($pageSpec) {
if (function_exists('curl_init')){
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
$ref = "http://www.google.com/";$ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_REFERER, $ref);$tmp = curl_exec ($ch);
curl_close ($ch);
$ret = $tmp;
}else{
$ret = @implode('', @file ($pageSpec));
}
return $ret;
}(...)
$stringpage = GetCurlPage($source);
(...)
Regards,
~ Bart ~