-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbitbucket-upload.php
109 lines (99 loc) · 4.62 KB
/
bitbucket-upload.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
<?php
require "include/bittorrent.php";
dbconn();
require_once(get_langfile_path());
loggedinorreturn();
parked();
if ($enablebitbucket_main != 'yes')
permissiondenied();
$maxfilesize = 256 * 1024;
$scaleh = 200; // set our height size desired
$scalew = 150; // set our width size desired
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$file = $_FILES["file"];
if (!isset($file) || $file["size"] < 1)
stderr($lang_bitbucketupload['std_upload_failed'], $lang_bitbucketupload['std_nothing_received']);
if ($file["size"] > $maxfilesize)
stderr($lang_bitbucketupload['std_upload_failed'], $lang_bitbucketupload['std_file_too_large']);
$pp=pathinfo($filename = $file["name"]);
if($pp['basename'] != $filename)
stderr($lang_bitbucketupload['std_upload_failed'], $lang_bitbucketupload['std_bad_file_name']);
$tgtfile = "$bitbucket/$filename";
if (file_exists($tgtfile))
stderr($lang_bitbucketupload['std_upload_failed'], $lang_bitbucketupload['std_file_already_exists'].htmlspecialchars($filename).$lang_bitbucketupload['std_already_exists'],false);
$size = getimagesize($file["tmp_name"]);
$height = $size[1];
$width = $size[0];
$it = $size[2];
switch ($it) {
case IMAGETYPE_GIF:
$orig=@imagecreatefromgif($file["tmp_name"]);
break;
case IMAGETYPE_JPEG:
$orig=@imagecreatefromjpeg($file["tmp_name"]);
break;
case IMAGETYPE_PNG:
$orig=@imagecreatefrompng($file["tmp_name"]);
break;
default:
stderr($lang_bitbucketupload['std_error'], $lang_bitbucketupload['std_invalid_image_format'],false);
die;
}
// Scale image to appropriate avatar dimensions
$hscale=$height/$scaleh;
$wscale=$width/$scalew;
$scale=($hscale < 1 && $wscale < 1) ? 1 : (( $hscale > $wscale) ? $hscale : $wscale);
$newwidth=floor($width/$scale);
$newheight=floor($height/$scale);
if(!$orig) {
stderr($lang_bitbucketupload['std_image_processing_failed'],$lang_bitbucketupload['std_sorry_the_uploaded']. image_type_to_extension($it) .$lang_bitbucketupload['std_failed_processing']);
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
if ($it == IMAGETYPE_PNG) {
$trans_colour = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
imagefill($thumb, 0, 0, $trans_colour);
}
imagecopyresampled($thumb, $orig, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
switch ($it) {
case IMAGETYPE_GIF:
$ret = imagegif($thumb, $tgtfile);
break;
case IMAGETYPE_JPEG:
$ret = imagejpeg($thumb, $tgtfile);
break;
case IMAGETYPE_PNG:
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
$ret = imagepng($thumb, $tgtfile);
break;
default:
die;
}
$url = str_replace(" ", "%20", htmlspecialchars(get_protocol_prefix()."$BASEURL/bitbucket/$filename"));
$name = sqlesc($filename);
$added = sqlesc(date("Y-m-d H:i:s"));
if ($_POST['public'] != 'yes' )
$public='"0"';
else
$public='"1"';
sql_query("INSERT INTO bitbucket (owner, name, added, public) VALUES ($CURUSER[id], $name, $added, $public)") or sqlerr(__FILE__, __LINE__);
update_user($CURUSER['id'], 'avatar = ?', [$url]);
stderr($lang_bitbucketupload['std_success'], $lang_bitbucketupload['std_use_following_url']."<br /><b><a href=\"$url\">$url</a></b><p><a href=bitbucket-upload.php>".$lang_bitbucketupload['std_upload_another_file']."</a>.<br /><br /><img src=\"$url\" border=0><br /><br />".$lang_bitbucketupload['std_image']. ($width=$newwidth && $height==$newheight ? $lang_bitbucketupload['std_need_not_rescaling']:$lang_bitbucketupload['std_rescaled_from']."$height x $width".$lang_bitbucketupload['std_to']."$newheight x $newwidth") .$lang_bitbucketupload['std_profile_updated'],false);
}
stdhead($lang_bitbucketupload['head_avatar_upload']);
?>
<h1><?php echo $lang_bitbucketupload['text_avatar_upload'] ?></h1>
<form method="post" action=bitbucket-upload.php enctype="multipart/form-data">
<table border=1 cellspacing=0 cellpadding=5>
<?php
if(!is_writable("$bitbucket"))
print("<tr><td align=left colspan=2>".$lang_bitbucketupload['text_upload_directory_unwritable']."</tr></td>");
print("<tr><td align=left colspan=2>".$lang_bitbucketupload['text_disclaimer']."$scaleh".$lang_bitbucketupload['text_disclaimer_two']."$scalew".$lang_bitbucketupload['text_disclaimer_three'].number_format($maxfilesize).$lang_bitbucketupload['text_disclaimer_four']);
?>
<tr><td class=rowhead><?php echo $lang_bitbucketupload['row_file'] ?></td><td class="rowfollow"><input type="file" name="file" size="60"></td></tr>
<tr><td colspan=2 align=left class="toolbox"><input class="checkbox" type=checkbox name=public value=yes><?php echo $lang_bitbucketupload['checkbox_avatar_shared']?> <input type="submit" value=<?php echo $lang_bitbucketupload['submit_upload'] ?>></td></tr>
</table>
</form>
<?php
stdfoot();