Skip to content

Instantly share code, notes, and snippets.

@codingfox-rus
Created August 2, 2015 13:14
Show Gist options
  • Save codingfox-rus/82286b8b65cf0ffb68e3 to your computer and use it in GitHub Desktop.
Save codingfox-rus/82286b8b65cf0ffb68e3 to your computer and use it in GitHub Desktop.
Загрузчик картинок для CKEditor
<?php
function getex($filename) {
return end(explode(".", $filename));
}
if($_FILES['upload']) {
if (($_FILES['upload'] == "none") || (empty($_FILES['upload']['name'])) ) {
$message = "Вы не выбрали файл";
} else if ($_FILES['upload']["size"] == 0 || $_FILES['upload']["size"] > 2050000) {
$message = "Размер файла не соответствует нормам";
} else if (($_FILES['upload']["type"] != "image/jpeg") && ($_FILES['upload']["type"] != "image/jpeg") && ($_FILES['upload']["type"] != "image/png")) {
$message = "Допускается загрузка только картинок JPG и PNG.";
} else if (!is_uploaded_file($_FILES['upload']["tmp_name"])) {
$message = "Что-то пошло не так. Попытайтесь загрузить файл ещё раз.";
} else {
$name = rand(1, 1000).'-'.md5($_FILES['upload']['name']).'.'.getex($_FILES['upload']['name']);
move_uploaded_file($_FILES['upload']['tmp_name'], "../img/upload/".$name);
$full_path = '/img/upload/'.$name;
$message = "Файл ".$_FILES['upload']['name']." загружен";
$size=@getimagesize('../img/upload/'.$name);
if($size[0]<50 OR $size[1]<50){
unlink('../img/upload/'.$name);
$message = "Файл не является допустимым изображением";
$full_path="";
}
}
$callback = $_REQUEST['CKEditorFuncNum'];
echo '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction("'.$callback.'", "'.$full_path.'", "'.$message.'" );</script>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment