-
-
Save alexbfree/5097308 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
<?php /* Copyright(c) 2013 Robert Maupin. Released under the ZLIB License. */ | |
if(count($_FILES) > 0) { | |
extract($_FILES['file']); | |
list($w,$h,$type)=getimagesize($tmp_name); | |
/*see exif-imagetype() documentation :) */ | |
if(!$type||$type>3||filesize($tmp_name)>1024*200) | |
exit(); | |
$ext=image_type_to_extension($type,false); | |
$md5=md5_file($tmp_name); | |
move_uploaded_file($tmp_name,$n="img/$md5.$ext"); | |
$i=call_user_func('imagecreatefrom'.$ext,$n); | |
$s=150;$r=$w/$h;$tw=$r<1?floor($s*$r):$s;$th=$r<1?$s:floor($s/$r); | |
$t=imagecreatetruecolor($tw,$th); | |
imagecopyresampled($t,$i,0,0,0,0,$tw,$th,$w,$h); | |
imagejpeg($t,"tmb/$md5.jpg",70); | |
imagedestroy($t); | |
exit(); | |
} | |
?><!DOCTYPE html><html><head><meta charset="UTF-8" /><title>µchan</title><style type="text/css"> | |
figure { | |
display: inline-block; | |
vertical-align:middle; | |
text-align:center; | |
padding: 10px; | |
margin: 0px | |
} | |
img { | |
padding:2px; | |
border:1px solid transparent | |
} | |
img:hover { | |
border:1px solid #ddd | |
}</style><script type="text/javascript">var d = document.documentElement; | |
d.ondragover=function(){return false;}; | |
d.ondragend=function(){return false;}; | |
d.ondrop=function(e){ | |
e.preventDefault(); | |
var fd=new FormData(); | |
fd.append('file', e.dataTransfer.files[0]); | |
var x=new XMLHttpRequest(); | |
x.open('POST','index.php',false); | |
x.onload=function(){location.reload();}; | |
x.send(fd); | |
return false; | |
};</script></head><body><?php | |
$g=glob("img/*",GLOB_NOSORT); | |
usort($g, create_function('$a,$b','return filemtime($b)-filemtime($a);')); | |
foreach($g as $f) { | |
extract(pathinfo($f)); | |
echo '<figure><a href="'.$f.'"><img src="tmb/'.$filename.'.jpg" alt=""></a></figure>'; | |
} | |
?></body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment