我是手动下载yii2uploadifywidget插件,可以上传,但是我翻遍了服务器该项目的每一个文件,都没有。每一次上传,除了会在后端dubeg目录下,添加一个.data文件外,没有任何其他上传文件。请师兄师姐们指点一下
这是controller层的代码,官方version2的源码
class TestController extends Controller
{
public function actions()
{
return [
'supload' => [
'class' => UploadAction::className(),
'basePath' => '@webroot/upload', //存放的磁盘目录
'baseUrl' => '@web/upload', //网站访问 url
'enableCsrf' => true, // default
'postFieldName' => 'Filedata', // default
//BEGIN METHOD
'format' => [$this, 'methodName'],
//END METHOD
//BEGIN CLOSURE BYHASH
'overwriteIfExist' => true,
'format' => function (UploadAction $action) { //处理上传数据文件名函数(不会建文件夹)
$fileext = $action>uploadfile>getExtension();
$filename = sha1_file($action>uploadfile>tempName);
return "{$filename}.{$fileext}";
},
//END CLOSURE BYHASH
//BEGIN CLOSURE BY TIME
'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}";
},
//END CLOSURE BY TIME
'validateOptions' => [
'extensions' => ['jpg', 'png'],
'maxSize' => 1 1024 1024, //file size
],
'beforeValidate' => function (UploadAction $action) {
//throw new Exception('test error');
},
'afterValidate' => function (UploadAction $action) {},
'beforeSave' => function (UploadAction $action) {},
'afterSave' => function (UploadAction $action) {
//$action>output
$action>output['fileUrl'] = $action>getWebUrl();
$action>output['fileName'] = $action>getFilename(); // "image/yyyymmddtimerand.jpg"
//www.smister.com/upload/images/aa.jpg
// $action>getWebUrl(); // "baseUrl + filename, /upload/image/yyyymmddtimerand.jpg"
$action>output['filePath'] = $action>getSavePath(); // "/var/www/htdocs/upload/image/yyyymmddtimerand.jpg"
},
],
];
}
}
这是视图文件index.php
//Remove Events Auto Convert
use yii\web\JsExpression;
use yii\helpers\Html;
use xj\uploadify\Uploadify;
echo "
";
echo "
";
echo "
";
//外部TAG
echo Html::fileInput('test', NULL, ['id' => 'test']);
echo Uploadify::widget([
'url' => \yii\helpers\Url::to(['supload']),
'id' => 'test',
'csrf' => true,
'renderTag' => false,
'jsOptions' => [
'width' => 120,
'height' => 40,
'onUploadError' => new JsExpression(<< function(file, errorCode, errorMsg, errorString) { console.log('The file ' + file.name + ' could not be uploaded: ' + errorString + errorCode + errorMsg); } EOF ), 'onUploadSuccess' => new JsExpression(<< function(file, data, response) { data = JSON.parse(data); if (data.error) { console.log(data.msg); } else { console.log(data.fileUrl); } } EOF ), ] ]); ?>
坑呀,帖子发了这么久了,都没有人回答,看来是没有新意了