-
Notifications
You must be signed in to change notification settings - Fork 0
/
up.php
163 lines (144 loc) · 4.52 KB
/
up.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
include "config.php";
include "class.m_img.php";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title><?php echo $c_title." - ".$c_tagline;?></title>
<link href="style.css" rel="stylesheet" type="text/css" />
<meta name="keywords" content="mobile upload images img tinyimghost tiny host" />
<meta name="description" content="TinyImgHost is an open-sourced image host made for mobile. its simple and fast." />
<script type="text/javascript">
</script>
</head>
<body>
<header>
<div class="logo">
<a href="index.php">
<h2><?php echo $c_title;?> - <span class="tag"><?php echo $c_tagline;?></span></h2>
</a>
</div>
<nav class="vertical menu">
<ul>
<?php if (false){?><li><a href="index.php">Upload</a></li><?php }?>
</ul>
</nav>
<div class="clear"></div>
</header>
<div class="content"><p>
<?php
//error_reporting(0);
if (!isset($_FILES["Filedata"]))
{
echo "ERROR:invalid upload";
exit(0); // Exit early, we don't have any file uploads, this page can only be opened via index.php
}
$message = array();
$names = "";
$m_img = new m_img;
$ip = $m_img->m_ip();
if ($m_img->m_isbannedip($ip)){
echo "ERROR:you are banned!";
exit(0);
}
foreach ($_FILES['Filedata']['name'] as $i => $name)
{
// Check for unknown errors:
if (!is_uploaded_file($_FILES["Filedata"]["tmp_name"][$i]) || $_FILES["Filedata"]["error"][$i] != 0)
{
$message[] = "ERROR 1: Unknown Error... ".$_FILES["Filedata"]["error"][$i];
}
// Set variables:
$m_img->m_name = $_FILES["Filedata"]["name"][$i];
$m_img->m_temp = "temp/".$m_img->m_name;
// Create temporary image:
copy($_FILES["Filedata"]["tmp_name"][$i], $m_img->m_temp);
// Init imagick object:
if ($m_img->is_use_imagick)
$img = new Imagick($m_img->m_temp);
else
$img = null;
// Get filetype:
$ext = $m_img->m_extension($m_img->m_name);
if ($c_debug_mode)
echo $ext;
$ext = strtolower($ext);
// Check for proper formats:
if ($ext != "bmp" && $ext != "jpg" && $ext != "jpeg" && $ext != "png" && $ext != "gif")
{
$message[] = "ERROR 2: Invalid File Type... ".$m_img->m_name."(".$ext.")"; // This is only thrown if javascript filter fails.
}
// If the image is BMP, convert it to PNG:
if ($ext == "bmp")
{
$tmpold = $m_img->m_temp;
$t_name = explode(".".$ext, $m_img->m_temp);
$m_img->m_temp = $t_name[0].".png";
$t_name = explode(".".$ext, $m_img->m_name);
$m_img->m_name = $t_name[0].".png";
rename($tmpold, $m_img->m_temp);
if ($m_img->is_use_imagick){
$img->setImageFormat("png");
$img->writeImage($m_img->m_temp);
$img->clear();
$img->destroy();
}
else{
$src = $m_img->ImageCreateFromBMP($target);
$orig_x = imageSX($src);
$orig_y = imageSY($src);
$temp = imagecreatetruecolor($orig_x,$orig_y);
imagealphablending($temp, false);
imagesavealpha($temp, true);
imagecopyresampled($temp,$src,0,0,0,0,$orig_x,$orig_x,$orig_x,$orig_y);
imagepng($temp, $m_img->m_temp);
imagedestroy($temp);
imagedestroy($src);
}
$ext = "png";
}
// This loop will rename a file until the name is not taken, it will also cut down a long filename:
do{
$m_img->m_name = $m_img->m_rename($m_img->m_name);
}while(file_exists("i/".$m_img->m_name)); // Cleverly ensure that rename is called once and only calls again if in the slight chance we randomly generate a taken name.
// Add name to list of names:
$names .= (empty($names)) ? $m_img->m_name : ",".$m_img->m_name;
// Set path variables here, instead of above due to m_rename's effect:
$path2destImg = "i/".$m_img->m_name;
$path2destThm = "t/".$m_img->m_name;
$path2destData = explode(".".$ext,$path2destImg);
$path2destData = $path2destData[0].".data";
file_put_contents($path2destData, base64_encode($ip));
// Copy temp image to destination.
copy($m_img->m_temp, $path2destImg);
$d = exif_imagetype($m_img->m_temp);
if ($c_debug_mode)
var_dump($d);
// Create thumbnail:
$r = $m_img->m_thumbnail($path2destImg, $path2destThm, $ext);
if ($c_debug_mode)
var_dump($r);
unlink($m_img->m_temp);
}
if (!empty($message))
{
echo "An error(s) occurred:<br/>";
foreach ($message as $m)
{
if ($c_debug_mode)
echo $m."</br>";
}
exit(0);
}
$m_img->m_refresh("index.php?m=v&i=".$names);
?></p>
<h4>Please Wait...</h4>
</div>
<footer>
<p class="copy">© 2014 Joe Jackson | All right reserved •</p>
</footer>
</body>
</html>