Created
July 16, 2014 15:25
-
-
Save tokune/62d6d2aad3fc8c4f5910 to your computer and use it in GitHub Desktop.
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
--- | |
name: flac | |
version: 2 | |
handle: | |
- rewrite: if(!is_file()) goto "index.php" | |
- compress: if(out_header["Content-Length"] >= 10240) compress | |
- compress: if(out_header["Content-Type"] ~ "text") compress | |
- compress: if(out_header["Content-Type"] ~ "application/javascript") compress | |
... |
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 | |
$kv = new SaeKV(); | |
$ret = $kv->init(); | |
function getFile($key) { | |
global $kv,$ret; | |
if ($key) { | |
$ret = $kv->get($key); | |
if (!$ret) { | |
notFound(); | |
} | |
header("Content-Type: application/x-octet-stream"); | |
echo $ret; | |
} | |
else { | |
notFound(); | |
} | |
} | |
function GetCurUrl() { | |
if(!empty($_SERVER["SCRIPT_URI"])) | |
{ | |
$scrtName = $_SERVER["SCRIPT_URI"]; | |
$nowurl = $scrtName; | |
} | |
else | |
{ | |
$scrtName = $_SERVER["PHP_SELF"]; | |
if(empty($_SERVER["QUERY_STRING"])) | |
{ | |
$nowurl = $scrtName; | |
} | |
else | |
{ | |
$nowurl = $scrtName."?".$_SERVER["QUERY_STRING"]; | |
} | |
} | |
return $nowurl; | |
} | |
function saveFile($info,$data) { | |
global $kv,$ret; | |
$key = md5(time().$info['name']); | |
$ret = $kv->add($key, $data); | |
return "http://flac.sinaapp.com/".$key; | |
} | |
function notFound() { | |
header('HTTP/1.1 404 Not Found'); | |
header("status: 404 Not Found"); | |
exit; | |
} | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
foreach ($_FILES as $info) { | |
$tmp_file = $info['tmp_name']; | |
if ($info['size'] / 1024 / 1024 <= 4) { | |
$fh = fopen($tmp_file, "rb"); | |
$data = fread($fh, filesize($tmp_file)); | |
fclose($fh); | |
$key = saveFile($info,$data); | |
echo $key; | |
} | |
else { | |
echo 'error'; | |
} | |
} | |
} | |
else { | |
$url = parse_url(GetCurUrl()); | |
$key = str_replace('/','',$url['path']); | |
if ($key) { | |
getFile($key); | |
} | |
else { | |
echo "tokune storage!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment