yii-starter-kit / yii2-file-kit Goto Github PK
View Code? Open in Web Editor NEWYii2 File storage and upload kit
Home Page: https://github.com/yii2-starter-kit/yii2-starter-kit
Yii2 File storage and upload kit
Home Page: https://github.com/yii2-starter-kit/yii2-starter-kit
I think the base_url should store in config files, do not need store in every db recorder.
{"name":"PHP Warning","message":"fclose(): 13 is not a valid stream resource","code":2,"type":"yii\base\ErrorException","file":"/var/www/html/goodwin-brothers/components/filesystem/StorageEngine.php","line":101,"stack-trace":["#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'fclose(): 13 is...', '/var/www/html/g...', 101, Array)","#1 /var/www/html/goodwin-brothers/components/filesystem/StorageEngine.php(101): fclose(Resource id #13)","#2 /var/www/html/goodwin-brothers/vendor/trntv/yii2-file-kit/src/actions/UploadAction.php(124): app\components\filesystem\StorageEngine->save(Object(yii\web\UploadedFile))","#3 [internal function]: trntv\filekit\actions\UploadAction->run()","#4 /var/www/html/goodwin-brothers/vendor/yiisoft/yii2/base/Action.php(92): call_user_func_array(Array, Array)","#5 /var/www/html/goodwin-brothers/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\Action->runWithParams(Array)","#6 /var/www/html/goodwin-brothers/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('upload', Array)","#7 /var/www/html/goodwin-brothers/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('file-storage/up...', Array)","#8 /var/www/html/goodwin-brothers/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))","#9 /var/www/html/goodwin-brothers/web/index.php(12): yii\base\Application->run()","#10 {main}"]}
How to change the files rights.
The name now is "blueimp/jquery-file-upload"
blueimp-file-upload is too old version can you update it?
thank you
yii2-flysystem
doesn't support flysystem-aws-s3-v3
, and the yii2-flysystem
package hasn't been updated for nearly a year.
What's currently the most efficient way to integrate flysystem-aws-s3-v3
with yii2-file-kit
?
It's sad that i can't preload my uploaded to model images in your Upload multiple widget.
So i made a little mod to Upload class:
"public $initial = false",
"if($this->initial){
foreach($this->initial as $ini){
$content .= Html::hiddenInput($this->name, $ini[$this->attribute]);
}
}" in run()
and 'initial'=>$model in view.
it loads images fine, but it's needed to be able to delete images from model.
It would be great if this ability were by default
This configuration:
'fileSystem' => [
'class' => 'creocoder\flysystem\LocalFilesystem',
'path' => '@webroot/storage'
],
'fileStorage'=> [
'class' => '\trntv\filekit\Storage',
'filesystemComponent'=> 'fileSystem',
'baseUrl' => '/storage',
],
leads to error
$storage = \Yii::$app->get('fileStorage');
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: trntv\filekit\Storage::filesystemComponent
Storage::$filesystemComponent should be public as well as Storage::$filesystem.
Не работает виджет при вызове формы в модальном окне (как это устроено в kartik-grid). input file работает как обычный загрузчик файлов в html без удобного интерфейса. В то же время, если попасть на форму без ajax то все работает отлично.
The message file for category 'app' does not exist: /usr/share/nginx/application/common/messages/es-CL/app.php Fallback file does not exist as well: /usr/share/nginx/application/common/messages/es/app.php
/usr/share/nginx/application/vendor/trntv/yii2-file-kit/src/widget/Upload.php (97)
/usr/share/nginx/application/backend/views/some-view/_form.php (48)
/usr/share/nginx/application/backend/views/some-view/update.php (19)
The problem is in this lines, because, at least in my application, the app
messages category doesn't exist.
If I'm not wrong translations should be kept in a sepparate messages folder.
Have a nice day!
Адаптер.
<?php
/**
* @author Artem Dekhtyar <[email protected]>
* 30.09.2015
*/
namespace common\components\filesystem;
use League\Flysystem\Filesystem;
use League\Flysystem\WebDAV\WebDAVAdapter;
use trntv\filekit\filesystem\FilesystemBuilderInterface;
/**
* Class WebDAVFlysystemBuilder
*/
class WebDAVFlysystemBuilder implements FilesystemBuilderInterface
{
public $path;
public $pathPrefix = '/extweb';
public function build()
{
\yii\base\Event::on(\trntv\filekit\Storage::className(), \trntv\filekit\Storage::EVENT_BEFORE_SAVE, function ($event) {
/** @var \trntv\filekit\Storage $storage */
$storage = $event->sender;
if (!$storage->getFilesystem()->has('.dirindex')) {
$storage->getFilesystem()->write('.dirindex', 1);
$dirindex = 1;
} else {
$dirindex = $storage->getFilesystem()->read('.dirindex');
}
if($storage->maxDirFiles !== -1) {
if($storage->getFilesystem()->has($dirindex)) {
$filesCount = count($storage->getFilesystem()->listContents($dirindex));
if ($filesCount > $storage->maxDirFiles) {
$dirindex++;
$storage->getFilesystem()->createDir($dirindex);
}
} else {
$storage->getFilesystem()->createDir($dirindex);
}
}
});
$client = new \Sabre\DAV\Client([
'baseUri' => 'https://webdav.yandex.ru',
]);
$client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
$client->addCurlSetting(CURLOPT_HTTPHEADER, [
'Authorization: OAuth TOKENTOKENTOKEN', // https://tech.yandex.ru/disk/doc/dg/concepts/quickstart-docpage/
'Accept: */*',
'Host: webdav.yandex.ru'
]);
$adapter = new WebDAVAdapter($client, '/');
$flysystem = new Filesystem($adapter);
if (!$flysystem->has($this->pathPrefix)) {
$flysystem->createDir($this->pathPrefix);
}
$adapter->setPathPrefix($this->pathPrefix);
return $flysystem;
}
}
И, на всякий случай, Sabre\HTTP\Client::createCurlSettingsArray() стр.426 портит установленые из вне хидеры. Но может, я в чём то не разобрался.
while trying to upload the profile picture (avatar) , the photos are uploaded correctly to the storage but giving 404 bad request , even in the demo page it give you internal server error while trying to edit the avatar from this url:
http://yii2-starter-kit.terentev.net/user/default/index
thank you.
if it has crop, it well great!!!!!!
addQuery(), addPath()
Hi. Whether there is an example of using the multiupload and attach many photos to model?
Hi
Maybe stupid question: how can I set permission for uploading files?
Now it is 600 ( -rw------- ), and I can't see where I can establish the rights clearly.
Please, help
The widget Upload
uses 'messagesCategory' with language en
,but there is no messages/en
in yii2-start-kit
.
'messages' => [
'maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded', [], 'en'),
'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed', [], 'en'),
'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large', [], 'en'),
'minFileSize' => Yii::t($this->messagesCategory, 'File is too small', [], 'en')
]
Examle file name "Форма 7 - Дополнительный сервис Имя сервиса" cut to "7 - Дополнительный сервис Имя сервиса" after upload
/**
* @inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
[
'class' => SluggableBehavior::className(),
'attribute' => 'name',
],
[
'class' => UploadBehavior::className(),
'attribute' => 'on_image',
'pathAttribute' => 'on_image_path',
'baseUrlAttribute' => 'on_image_base_url',
],
[
'class' => UploadBehavior::className(),
'attribute' => 'off_image',
'pathAttribute' => 'off_image_path',
'baseUrlAttribute' => 'off_image_base_url',
],
];
}
i want to store in different directory.
for on_image to @storage/web/product/on_images,
off_image to @storage/web/product/off_images
I'vr just installed your starter kit package and I couldn't upload images.
I've updated bower-asset/blueimp-file-upload from ~9.7.0 to ~9.10.5 and it works fine now, maybe you should update to a later version as well.
~
Is there any way to get the model id for saved file on fileProcessing?
Hi Eugene,
Somehow my file upload setup seems to make my small images (mostly about 4kb) pixelated.
I'm not sure if they are processed in any way but what I would really like is that they are not resized at all or processed in any way. How can I achieve that?
Regards and thanks for your help,
Adam
PRESENT CONFIG
'avatar-upload' => [
'class' => UploadAction::className(),
'deleteRoute' => 'avatar-delete',
'on afterSave' => function ($event) {
/* @var $file \League\Flysystem\File */
$file = $event->file;
$img = ImageManagerStatic::make($file->read())->fit(382, 215);
$file->put($img->encode());
}
],
enhanced feature for choose option
i have condition where the files must be uploading when only form submitting
Don't know what to do
'fs' => [
'class' => 'creocoder\flysystem\LocalFilesystem',
'path' => '@backend/uploads'
],
'fileStorage' => [
'class' => 'trntv\filekit\Storage',
'baseUrl' => '@backend/uploads',
'filesystemComponent' => 'fs'
],
Error:
{"name":"PHP Recoverable Error","message":"Argument 1 passed to League\Flysystem\Handler::__construct() must implement interface League\Flysystem\FilesystemInterface, instance of creocoder\flysystem\LocalFilesystem given, called in /home/www-data/www/iptool/vendor/trntv/yii2-file-kit/src/actions/UploadAction.php on line 130 and defined","code":4096,"type":"yii\base\ErrorException","file":"/home/www-data/www/iptool/vendor/league/flysystem/src/Handler.php","line":23,"stack-trace":["#0 /home/www-data/www/iptool/vendor/league/flysystem/src/Handler.php(23): yii\base\ErrorHandler->handleError(4096, 'Argument 1 pass...', '/home/www-data/...', 23, Array)","#1 /home/www-data/www/iptool/vendor/trntv/yii2-file-kit/src/actions/UploadAction.php(130): League\Flysystem\Handler->__construct(Object(creocoder\flysystem\LocalFilesystem), '1/Hkgy9UC3yhwhy...')","#2 [internal function]: trntv\filekit\actions\UploadAction->run()","#3 /home/www-data/www/iptool/vendor/yiisoft/yii2/base/Action.php(92): call_user_func_array(Array, Array)","#4 /home/www-data/www/iptool/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\Action->runWithParams(Array)","#5 /home/www-data/www/iptool/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('upload', Array)","#6 /home/www-data/www/iptool/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('file/upload', Array)","#7 /home/www-data/www/iptool/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))","#8 /home/www-data/www/iptool/backend/web/index.php(18): yii\base\Application->run()","#9 {main}"]}
Thanks in advance
Hi,
sorry to bother you, but I had simple question about this file kit. I installed the yii starter kit that has this and when I upload a file the permissions are set to 600. The starter kit also has the file manager with it and it does not have this issue. So is there a place to set the upload permissions or is this dependent on my server somehow? What could be causing this?
Thanks
Каким образом можно корректно сделать редирект на определенный action после загрузки файла на странице вывода виджета. Т.е можно ли передать и как параметр для редиректа аналогично указанию размера файла или его расширения (maxFileSize, acceptFileTypes)?
Hi,
on the file \vendor\trntv\yii2-file-kit\src\widget\Upload.php
I see there attribute for specifying types needed , how can I use this I tried some regular expressions and file types and nothing succeeded .
Also, on \vendor\trntv\yii2-file-kit\src\actions\UploadAction.php
there array for validationRules how I can use it ..
thank you a lot for your contributions in building such kits.
best regards,
Fady
Default repository should be defined.
Repository routes based on categories
Добрый день!
При загрузке файлов на сервер происходит конфликт с названием полей.
В моей модели, куда я подгружаю картинку, существуют поля: name, type.
array (size=3)
'_csrf' => string 'ZlIzYXpGMFYQJVozTgN.FSNraVZOB18cFz9RIkwfBCMpOGIISHBAAg==' (length=56)
'Company' =>
array (size=13)
'type' => string '2' (length=1)
'name' => string '23423432' (length=8)
'picture' =>
array (size=6)
'path' => string '1/WMi3_hcCuNvxd3RqX_AYfM2inifNRdBZ.png' (length=38)
'name' => string ' экрана_2015-04-29_00-44-43' (length=33)
'size' => string '465063' (length=6)
'type' => string 'image/png' (length=9)
'order' => string '' (length=0)
'base_url' => string 'http://storage.maritime.dev/source' (length=34)
'phone' => string '' (length=0)
'email' => string '[email protected]' (length=19)
'skype' => string '' (length=0)
'site' => string '' (length=0)
'city_id' => string '' (length=0)
'country_id' => string '' (length=0)
'adress' => string '' (length=0)
'text' => string '' (length=0)
'created_by' => string '1' (length=1)
'contact_person' => string '' (length=0)
'_fileinput_w1' => string '' (length=0)
При сохранении модели эти поля заполняются из данных о загруженном файле. Содержимое Company['picture']['name'] заменяет содержимое Company['name'], с Type та же проблема..
How can i use upload relations for junction tables.
it works fine for one to many relation, as you did in backend articles.
But how can i use it for many to many relations.
Used in profile in yii2-starter-kit as widget.
$form->field($model, 'picture')->widget(\trntv\filekit\widget\SingleFileUpload::classname(), [
'url' => ['avatar-upload', 'category' => 'avatar']
])
Sends UserProfile[picture] param three times.
POST params:
UserProfile[picture] http://storage.aqstarter.local/1/OkJfV6z79Na3tTQ8Fk88BMoJgMc6NqOS.png
UserProfile[picture]
UserProfile[picture]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.