Skip to content

Instantly share code, notes, and snippets.

@VitaliiTsilnyk
Created April 16, 2012 13:27
Show Gist options
  • Save VitaliiTsilnyk/2398793 to your computer and use it in GitHub Desktop.
Save VitaliiTsilnyk/2398793 to your computer and use it in GitHub Desktop.
Gyazo php uploader
<?php
/**
* Gyazo php uploader
*
* @author Neris Ereptoris <www.neris.ws>
* @copyright 2010
*
* @version 0.1
* @link http://neris.ws/
*/
//TODO: Error handling
$upload_dir_ulr = "http://example.com/g/";
$error_page_url = $upload_dir_ulr . "error.html";
$max_file_size = 1024 * 1024 * 4; // 4MB
$upload_dir_name = dirname(__FILE__) . "/";
$user_id = "insert your secret password here";
if ( !isset($_POST["id"]) || empty($_POST["id"]) )
{
exit($error_page_url . "#id-not-found");
}
if ( $_POST["id"] != $user_id )
{
exit($error_page_url . "#wrong-id");
}
if ( !isset($_FILES["imagedata"]["size"]) )
{
exit($error_page_url . "#size-not-found");
}
if ( intval($_FILES["imagedata"]["size"]) > $max_file_size )
{
exit($error_page_url . "#image-is-too-big");
}
$new_file_name = md5($_FILES['imagedata']['tmp_name'] . time()) . ".png";
if ( !move_uploaded_file($_FILES['imagedata']['tmp_name'], $upload_dir_name . $new_file_name) )
{
exit($error_page_url . "#can-not-move-uploaded-file");
}
echo $upload_dir_ulr . $new_file_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment