-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoutes.php
47 lines (34 loc) · 1015 Bytes
/
Routes.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
<?php
//Routes.php
Route::post('/eein/wysiwyg/upload/{slug}/', function($slug){
/**
* Upload directory
*/
//create directory if doesn't exist
define("UPLOADDIR", "./uploads/public/wysiwyg/" . $slug . "/");
if (!file_exists(UPLOADDIR)) {
mkdir(UPLOADDIR, 0777, true);
}
// Detect if it is an AJAX request
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$file = array_shift($_FILES);
if(move_uploaded_file($file['tmp_name'], UPLOADDIR . basename($file['name']))) {
$file = dirname($_SERVER['PHP_SELF']) . str_replace('./', '/', UPLOADDIR) . $file['name'];
$data = array(
'message' => 'uploadSuccess',
'file' => $file,
);
} else {
$error = true;
$data = array(
'message' => 'uploadError',
);
}
} else {
$data = array(
'message' => 'uploadNotAjax',
'formData' => $_POST
);
}
echo json_encode($data);
});