#!/usr/bin/php -Cq 0) { if (!($fp = @fopen($url, 'r'))) { return NULL; } $meta = stream_get_meta_data($fp); for ($j = 0; isset($meta['wrapper_data'][$j]); $j++) { if (strstr(strtolower($meta['wrapper_data'][$j]), 'last-modified')) { $modtime = substr($meta['wrapper_data'][$j], 15); break; }//end if }//end for fclose($fp); } else { $parts = parse_url($url); $host = $parts['host']; $path = $parts['path']; if (!($fp = @fsockopen($host, 80))) { return NULL; } $req = "HEAD $path HTTP/1.0\r\nUser-Agent: PHP/".phpversion()."\r\nHost: $host:80\r\nAccept: */*\r\n\r\n"; fputs($fp, $req); while (!feof($fp)) { $str = fgets($fp, 4096); if (strstr(strtolower($str), 'last-modified')) { $modtime = substr($str, 15); break; }//end if }//end while fclose($fp); }//end if return isset($modtime) ? strtotime($modtime) : time(); } // The 3:rd argumnent is set from the source - assumed to be an URL, use as // if (! download($url, $file_target, &$modified)) { ... } function download($url, $file_target, $modified) { if (function_exists('version_compare') && version_compare(phpversion(), '4.3.0') > 0) { $modified = -1; // We will do this later, on the open filehandle below } else { $modified = stream_last_modified($url); } $rh = fopen($url, 'rb'); if ($rh===false) { return true; }//end if if ($modified < 0) { $meta = stream_get_meta_data($rh); for ($j = 0; isset($meta['wrapper_data'][$j]); $j++) { if (strstr(strtolower($meta['wrapper_data'][$j]), 'last-modified')) { $modtime = substr($meta['wrapper_data'][$j], 15); break; }//end if }//end for $modified = isset($modtime) ? strtotime($modtime) : time(); }//end if $wh = fopen($file_target, 'wb'); if ($wh===false) { return true; }//end if while (!feof($rh)) { if (fwrite($wh, fread($rh, 1024)) === FALSE) { // 'Download error: Cannot write to file ('.$file_target.')'; return true; }//end if }//end while fclose($rh); fclose($wh); if (touch($file_target, $modified)) { print "$file_target modification time has been adjusted to $modified\n"; } else { print "Sorry, could not change modification time of $file_target\n"; }//end if // No error return false; } #print_r($argv); #$url=$argv[1]; #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/AAU1-051222.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/2-uuaa.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa3-060103.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa4-061230.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa5-0601003.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/UUAA6-060105.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/UUAA7-060108.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa8-060111b.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa9-060117.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa10-060120.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa11-060123.m4a"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa11-060123.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa12-060129a.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa12-060129b.mp3"); #$url = escapeshellcmd ("http://d663187.u33.surftown.se/uuaa/uuaa12-060129c.mp3"); print $url . "\n"; if (preg_match('/([^\/]+?)$/', $url, $preg_matches, PREG_OFFSET_CAPTURE)) { print_r($preg_matches); print "MATCH = \"" . $preg_matches[0] . "\"\n"; print "FILEPART = \"" . $preg_matches[1] . "\"\n"; $filename = $preg_matches[1]; } else { $filename = "url_last_modified_timestamp"; } $modified = stream_last_modified($url); print $filename . "\n"; print $modified . "\n"; if (touch(getcwd() . "/" . $filename, $modified)) { print "$filename modification time has been adjusted to $modified\n"; } else { print "Sorry, could not change modification time of $filename\n"; }//end if ?>