Created
March 17, 2012 06:18
-
-
Save JaHIY/2055724 to your computer and use it in GitHub Desktop.
PHP:Upload pictures to SAE (based on http://blog.4321.la/articles/2012/02/12/use-sae-to-setup-uploading-system/ )
This file contains hidden or 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 | |
define('PASSWORD','putyourpasswordhere'); | |
define('DOMAIN','h'); | |
function extend($file_name) { | |
$extend = pathinfo($file_name); | |
$extend = strtolower($extend["extension"]); | |
return $extend; | |
} | |
if ($_POST["pw"] !== PASSWORD) { | |
echo "fuck!"; | |
} else { | |
$target_path = SAE_TMP_PATH; | |
$basename = basename( $_FILES['file']['name']); | |
$uuid = md5(uniqid(rand(), true)); | |
$target_path = $target_path.$uuid; | |
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path) == false) { | |
echo "There was an error uploading the file, please try again!\n"; | |
} | |
/*$file_contents = file_get_contents($target_path); | |
$s = new SaeStorage(); | |
$filename=$uuid.$basename; | |
$s->write($domain, $filename ,$file_contents); | |
$url=$s->getUrl($domain, $filename);*/ | |
$extends = array("jpg","jpeg","gif","png","bmp"); | |
$extend = extend($basename); | |
if (in_array($extend,$extends)) { | |
$s = new SaeStorage(); | |
echo $s->upload(DOMAIN, $uuid.".".$extend,$target_path)."\n"; | |
//echo $url; | |
} else { | |
echo "Invalid file!\n"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment