forked from anand-patel/oc-wysiwyg-editors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.php
73 lines (62 loc) · 1.99 KB
/
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
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
<?php
use Backend\Facades\BackendAuth;
/**
* Filter to Authenticate Backend User
*/
Route::filter('authenticate', function()
{
if (!BackendAuth::check()) {
return "You don`t have permission to access this page!!!";
}
});
/**
* Routes for Froala
*/
Route::group(['before' => 'authenticate'], function()
{
/**
* Froala image upload
*/
Route::post('image_upload', function() {
// Allowed extentions.
$allowedExts = ['gif', 'jpeg', 'jpg', 'png'];
// Get filename.
$temp = explode('.', $_FILES['file']['name']);
// Get extension.
$extension = end($temp);
// An image check is being done in the editor but it is best to
// check that again on the server side.
// Do not use $_FILES['file']['type'] as it can be easily forged.
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['file']['tmp_name']);
if ((($mime == 'image/gif')
|| ($mime == 'image/jpeg')
|| ($mime == 'image/pjpeg')
|| ($mime == 'image/x-png')
|| ($mime == 'image/png'))
&& in_array($extension, $allowedExts)
) {
// Generate new random name.
$name = sha1(microtime()).'.'.$extension;
// Save file in the uploads folder.
move_uploaded_file($_FILES['file']['tmp_name'], getcwd().'/storage/app/media/'.$name);
// Generate response.
$response = new StdClass;
$response->link = asset('/storage/app/media/'.$name);
echo stripslashes(json_encode($response));
}
});
/**
* Froala image delete
*/
Route::post('delete_image', function()
{
// Get src.
$src = basename($_POST['src']);
// Check if file exists.
if (file_exists(getcwd().'/storage/app/media/'.$src)) {
// Delete file.
unlink(getcwd().'/storage/app/media/'.$src);
}
});
});