PHP
27 Nov 2010
 

Gyazo php uploader

 
 
 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
<?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;