public
Last active

A very tiny image gallery.

  • Download Gist
index.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<?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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.