Last active
August 29, 2015 13:58
-
-
Save KohsukeHada/9974088 to your computer and use it in GitHub Desktop.
ローカル サーバ内のファイル サイズを返すPHP コード。jquery.file.size-extension.js と組み合わせて使用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//ローカル サーバ内のファイル サイズを返す | |
$root = "/http_root_dir/"; //URLのルートにあたるサーバのローカル ディレクトリ | |
$url = $_GET['url']; //URLパラメータ | |
$parse_url_arr = parse_url ( $url ); //URLをパース | |
$path = $root.$parse_url_arr['path']; //URLからパスを取得してローカル ディレクトリを取得 | |
$size = filesize($path); //ファイルサイズを取得 | |
//ファイル サイズが取得できない場合 -1 を返す | |
if($size == false) { | |
$size = -1; | |
} | |
$output = array( | |
"size"=> (string)$size | |
); | |
//コールバック | |
header( 'Content-Type: text/javascript; charset=utf-8' ); | |
echo $_GET['callback'] . "(" . json_encode($output). ")"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment