Last active
July 26, 2017 09:36
-
-
Save swuppio/5158d6935d2e74fbf8bc039b5e4302bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\models; | |
use Yii; | |
use yii\base\Model; | |
use yii\web\UploadedFile; | |
class Uploader extends Model | |
{ | |
public $img; | |
public function rules() | |
{ | |
return [ | |
[['img'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, jpeg'], | |
]; | |
} | |
public static function uld() { | |
$model = new self; | |
$model->img = UploadedFile::getInstanceByName('upload'); | |
if (!$model->validate()) $message = $model->errors; | |
$filename = date('d.m.Y_').rand(0, PHP_INT_MAX).'.'.$model->img->extension; | |
$path_dir = Yii::getAlias('@webroot/img/editor/'); | |
if (!is_dir($path_dir)) mkdir($path_dir); | |
$full_path = $path_dir.$filename; | |
$link = Yii::getAlias('@web/img/editor/'); | |
if(@$model->img->saveAs($full_path)){ | |
$message = "Файл загружен"; | |
} else $message = 'Не удалось сохранить файл(ы). Не найденный путь: '.$full_path; | |
$callback = $_REQUEST['CKEditorFuncNum']; | |
echo '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction("'.$callback.'", "'.$link.$filename.'", "'.$message.'" );</script>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment