Skip to content

Instantly share code, notes, and snippets.

@synchrone
Last active January 2, 2016 17:59
Show Gist options
  • Save synchrone/8340425 to your computer and use it in GitHub Desktop.
Save synchrone/8340425 to your computer and use it in GitHub Desktop.
Gyazo hosting
server { #generic php-fpm setup, really
server_name i;
root /var/www/i/www;
client_max_body_size 20m;
index index.php index.htm index.html;
location ~ ^.+\.php$ {
if ( -f $document_root/../maintenance) {
return 503;
}
#fastcgi_pass 127.0.0.1:9000;
#or
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php;
}
}
<?php
if(isset($_FILES['imagedata'])){
$storage = 'i/';
$ext = 'png';
$id=sha1(file_get_contents($_FILES['imagedata']['tmp_name']));
move_uploaded_file($_FILES['imagedata']['tmp_name'],sprintf('%s%s.%s',$storage,$id,$ext));
$url = sprintf('http://%s/i/%s.%s',$_SERVER["HTTP_HOST"],$id,$ext);
if(strpos($_SERVER["HTTP_USER_AGENT"],'Gyazo')!==false){
echo $url;
}else{
header('Location: '.$url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment