「外部のサーバーにあるファイルの、ファイルサイズ」
を得る方法があれば、お願いします。
filesize関数を使ってみましたが、
実行するphpと別のサーバーにあるファイル(zipやexeなど)のサイズは得られませんでした。
例えば、
vectorにある特定のソフトのファイルサイズを取得して、
phpで表示する、というようなイメージです。
httpでgetを投げて、Content-Lengthヘッダを取得すればよいのでは?
function getfs($request, $host){
$fp = fsockopen($host, 80);
fwrite($fp, $request);
$response = '';
while (!feof($fp) and !preg_match('/\r\n\r\n/',$response)) {
$response .= fgets($fp, 1024);
}
fclose($fp);
if(preg_match('/Content-Length: ([[:digit:]]+)/', $response, $mat)){
return $mat[1];
}else{
return -1;
}
}
echo(getfs("GET /pack/winnt/util/backup/tih_d_n.exe HTTP/1.0\r\nHost: ftp.vector.co.jp\r\nConnection: close\r\n\r\n", 'ftp.vector.co.jp'));
httpでgetを投げて、Content-Lengthヘッダを取得すればよいのでは?
function getfs($request, $host){
$fp = fsockopen($host, 80);
fwrite($fp, $request);
$response = '';
while (!feof($fp) and !preg_match('/\r\n\r\n/',$response)) {
$response .= fgets($fp, 1024);
}
fclose($fp);
if(preg_match('/Content-Length: ([[:digit:]]+)/', $response, $mat)){
return $mat[1];
}else{
return -1;
}
}
echo(getfs("GET /pack/winnt/util/backup/tih_d_n.exe HTTP/1.0\r\nHost: ftp.vector.co.jp\r\nConnection: close\r\n\r\n", 'ftp.vector.co.jp'));
ありがとうございます。
試してみたところ、無事動作しました!
vector以外のファイルでも試しましたが、動作しました。
どうもありがとうございました。
$file_url = 'http://my.vector.co.jp/servlet/System.FileDownload/download/http/0/86280/pack/win95/writing/edit/hm/maruo609_signed.exe' ; $url_headers = get_headers($file_url) ; while ($one = array_shift($url_headers)) { if ($one == 'HTTP/1.1 200 OK') break ; } while ($one = array_shift($url_headers)) { if (preg_match('/^Content-Length: (\d+)/', $one, $matches)) { $size = $matches[1] ; break ; } } echo $size ;
ひとつだけしか試してませんが。
ありがとうございます。
試してみたところ、get_headersはphp5の関数なのですね。
バージョンアップが面倒なので4系をそのまま使っていましたが・・・。
やはり便利な関数が多いみたいなので、移行して使ってみたいと思います。
どうもありがとうございました。
ありがとうございます。
試してみたところ、無事動作しました!
vector以外のファイルでも試しましたが、動作しました。
どうもありがとうございました。