-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
executable file
·53 lines (44 loc) · 1.58 KB
/
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
<?php
function upload($file) {
// Optional: instance name (might be used to adjust the server folders for example)
$CKEditor = $_GET['CKEditor'] ;
// Required: Function number as indicated by CKEditor.
$funcNum = $_GET['CKEditorFuncNum'] ;
// Optional: To provide localized messages
$langCode = $_GET['langCode'] ;
/**
* Charger le fichier
*/
$url = '' ;
// Optional message to show to the user (file renamed, invalid file, not authenticated...)
$message = '';
$dir = __DIR__;
$dir .= "/uploads/";
$extensions = array('.png', '.gif', '.jpg', '.jpeg');
$maxsize = 200000;
$filename = $file['tmp_name'];
$extension = strtolower(strrchr($file['name'], '.'));
$size = $file['size'];
if (!file_exists($filename)) {
$error = "Image non trouvée";
}else{
if(!in_array($extension, $extensions)){
$error = "Image non valide";
}
if($size > $maxsize){
$error = "Image trop grande max 200ko";//"Taille max : 100Ko ";
}
}
if(isset($error)){
$message = $error;
echo "<script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message')</script>";
}else{
$fichier = uniqid().$extension;
$url = 'uploads/'.$fichier;
if(move_uploaded_file($filename, $dir.$fichier)){
echo "<script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message')</script>";
}
}
}
upload($_FILES['upload']);
?>