<?php
namespace
\backend\controllers;
use
xj\uploadify\UploadAction;
class
TestController
extends
\yii\web\Controller
{
public
function
actions() {
return
[
's-upload' => [
'
class
' => UploadAction::className(),
'basePath' => '@webroot/upload',
'baseUrl' => '@web/upload',
'enableCsrf' => true,
'postFieldName' => 'Filedata',
'format' => [
$this
, 'methodName'],
'overwriteIfExist' => true,
'format' =>
function
(UploadAction
$action
) {
$fileext
=
$action
->uploadfile->getExtension();
$filename
= sha1_file(
$action
->uploadfile->tempName);
return
"{$filename}.{$fileext}"
;
},
'format' =>
function
(UploadAction
$action
) {
$fileext
=
$action
->uploadfile->getExtension();
$filehash
= sha1(uniqid() . time());
$p1
=
substr
(
$filehash
, 0, 2);
$p2
=
substr
(
$filehash
, 2, 2);
return
"{$p1}/{$p2}/{$filehash}.{$fileext}"
;
},
*/
'validateOptions' => [
'extensions' => ['jpg', 'png'],
'maxSize' => 1 * 1024 * 1024,
],
'beforeValidate' =>
function
(UploadAction
$action
) {
},
'afterValidate' =>
function
(UploadAction
$action
) {},
'beforeSave' =>
function
(UploadAction
$action
) {},
'afterSave' =>
function
(UploadAction
$action
) {
$action
->output[‘fileUrl’] =
$action
->getWebUrl()
},
],
];
}
}
?>