有了这段代码,我可以得到修改时间,但我需要得到最后修改的文件名,所以有人能告诉我怎么做吗?
function filemtime_remote($uri)
{
$uri = parse_url($uri);
$handle = @fsockopen($uri['host'],80);
if(!$handle)
return 0;
fputs($handle,"GET $uri[path] HTTP/1.1'r'nHost: $uri[host]'r'n'r'n");
$result = 0;
while(!feof($handle))
{
$line = fgets($handle,1024);
if(!trim($line))
break;
$col = strpos($line,':');
if($col !== false)
{
$header = trim(substr($line,0,$col));
$value = trim(substr($line,$col+1));
if(strtolower($header) == 'last-modified')
{
$result = strtotime($value);
break;
}
}
}
fclose($handle);
return $result;
}
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$result = "1";
$html = get_data("http://mysite.ir/api.php?uid=". $result); //the result is r1&r2&r3&r4&....
$matches[1] = explode("&", $html);
if(!empty($matches[1])){
$errorMessage .= "DONE";
//Need Help here
$last_modified_file = filemtime_remote($matches[1]); //its just return modification time i need the last modified file name!!
}
您不能这样做,除非远程服务器提供一个脚本,该脚本允许您给它一个文件名,并返回从本地文件系统中获取的mtime。