Hi想检查一些远程文件大小的文件大小,在localhost.But中正常工作的csize函数下,当我在google引擎中托管时,我发现我没有使用support.so,我使用了purl wrapper.Still,我遇到了错误。
我听说可以在gae file..if中使用java,那么在java中是否有任何函数来获取远程文件的文件大小?如果是这样的话,如何在php中使用它。
<?php
require_once 'Purl.php';
echo csize('http://www.example.com');
function csize($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
return $size;
}发布于 2014-11-24 06:10:29
只需使用http streams API
function csize($url) {
$options = ['http' => [
'method' => 'HEAD',
],
];
$ctx = stream_context_create($options);
$result = file_get_contents($url, false, $ctx);
if ($result !== false) {
foreach($http_response_header as $header) {
if (preg_match("/Content-Length: (\d+)/i", $header, $matches)) {
return $matches[1];
}
}
}
}https://stackoverflow.com/questions/27094889
复制相似问题