forked from buckyroberts/Social-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sceditoruploader.php
53 lines (43 loc) · 1.74 KB
/
sceditoruploader.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
<?php
/**
* Upload Photo Using Jquery uploadify plugin
* This will handle sceditor image uploading logic
*/
require(dirname(__FILE__) . '/includes/bootstrap.php');
/*if( !($userID = buckys_is_logged_in()) )
{
buckys_redirect('/index.php', MSG_NOT_LOGGED_IN_USER, MSG_TYPE_ERROR);
}
*/
if(!empty($_FILES)){
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = DIR_FS_FORUM_USER_UPLOAD_IMG . date('Y-m-d') . "/"; // temp files
if(!is_dir($targetPath)){
mkdir($targetPath, 0777);
//Create Index.html to prevent directory listing issue
$fp = fopen($targetPath . "/index.html", "w");
fclose($fp);
}
// Validate the file type
$fileParts = pathinfo($_FILES['Filedata']['name']);
//Check the file extension
if(in_array(strtolower($fileParts['extension']), $TNB_GLOBALS['imageTypes'])){
//Check Image Size
list($width, $height, $type, $attr) = getimagesize($tempFile);
if(!in_array($type, [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG])){
echo json_encode(['success' => 0, 'msg' => MSG_INVALID_PHOTO_TYPE]);
exit;
}
if($width > MAX_IMAGE_WIDTH || $height > MAX_IMAGE_HEIGHT){
echo json_encode(['success' => 0, 'msg' => MSG_PHOTO_MAX_SIZE_ERROR]);
}else{
$targetFileName = md5(uniqid()) . "." . $fileParts['extension'];
$targetFile = $targetPath . $targetFileName;
move_uploaded_file($tempFile, $targetFile);
$imageURI = str_replace(DIR_FS_ROOT, '/', $targetPath);
echo json_encode(['success' => 1, 'file' => $imageURI . $targetFileName]);
}
}else{
echo json_encode(['success' => 0, 'msg' => MSG_INVALID_PHOTO_TYPE]);
}
}