Git Product home page Git Product logo

yii2-attachments's People

Contributors

abriosi-benassi avatar ctolet avatar desher avatar dmkdesign avatar drtsb avatar jeffwalsh avatar marsuboss avatar maxxer avatar muhammadcahya avatar rapita avatar sap55 avatar sokollondon avatar zacksleo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-attachments's Issues

Checklist for more flexible and stable version 2

Features, bugs and enhancements:

  • Test correct saving of the files with hieroglyphs (like Chinese)
  • All file manipulations works via AJAX
  • Сode coverage of the most source code
  • Configurable upload and temp path per model (issue #32)
  • Solve a problem with removing files and adding another few before first submit (issue #17)
  • Required rule (issue #37)
  • Make components ovverridable, use DI

How to add dynamic location

Currently the location for uploaded file is set by random directory with md5(microtime(true) . $filePath)

How to set with custom location like path/attribute_id/attribute_2/etc... ?

Не сохраняет в базу данных

Привет ещё раз, живём в России, так что предлагаю общаться по русски. Перерыл всё расширение, всё вроде правильно сделал. всё работает, кроме сохранения изображений в базу данных. Использую yii2 basic

Only image types show in gallery list [Widget AttachmentsTableWithPreview]

I use attachment with image and office (pdf,word,excel, ppt, etc)
For the non image type file, AttachmentsTableWithPreview widget still show up this type

I think only image file should show in colorbox-widget, for non image can open in new tab, or etc
Because some user who use, is thinking all file type must show in colorbox-widget, and if colorbox-widget not show preview of the file, user says the file is not exist

Yii2 attachment module not found

I installed the extension, and did everything according to the instructions, but with yii migrate / up I get an error that the module was not found

when uploaded file has no extension upload failes (type cannot be empty in model)

I know this might not be of much use to many, though if the uploaded file has no extension the upload fails 'cause the type (fileType) field is empty and this is not allowed...

Using windows this probably would never get triggered, though using linux as a client it might create problems (as files are not interpreted by the extension but by it's content mimetype)

no relation named "uploadForms"

Hi

Invalid Parameter – yii\base\InvalidParamException
common\models\Post has no relation named "uploadForms".

Any clue?

Folder not deleted

Hi Nemmo,
When i delete any image, the corresponding folder doesn´t delete.

Thanks and excellent work!
Lks

[Question] Widget AttachmentsTableWithPreview

What is it the hell code?

        $hasFileBehavior = false;
        foreach ($this->model->getBehaviors() as $behavior) {
            if ($behavior->className() == FileBehavior::className()) {
                $hasFileBehavior = true;
            }
        }

Why not used instanceof?

Configurable upload and temp path per model

Is there a way to configure upload and temp path per model. For example when i attach files to user i need to have path like avatars/user1/... and on documents i need to have path like documents/pdf/....
How could i achieve such a functionality?

Using in GridView

Do you have any idea how to use your extension in conjunction with Katik's GridView (which for these purposes is not much different from the plain Yii2 GridView)? I've tried this approach (which I don't like because, lacking the ability to set one image a primary, I just want the first image) which simply produces a "(not set)":

'columns'      => [
                    [
                        'class' => '\kartik\grid\SerialColumn'
                    ],
                   [
                        'attribute' => 'files',
                        'label' => false,
                        'format' => 'raw',
                        'value' => function($data) {
                            foreach ($data->files as $file) {
                                echo Html::img($file->path);
                            }
                        }
                    ],
                    'name',
                    [
                        'attribute' => 'source',
                        'format'    => 'raw',
                        'label'     => 'Source',
                        'value'     => function ($data) {

                            return Html::a(Html::encode($data->source), $data->source_url, ['target' => '_blank']);
                        },
                    ],
...

I've also tried this approach which produces a "Undefined offset: 0" error:

[
                        'attribute' => 'files',
                        'label' => false,
                        'format' => 'raw',
                        'value' => function($data) {
                            echo Html::img($data->files[0]->path);
                        }
                    ],

I've also tried this approach which produces a "Setting unknown property: nemmo\attachments\components\AttachmentsTable::data" error. (The data when setting value like this is in $data, not $model):

'columns'      => [
                    [
                        'class' => '\kartik\grid\SerialColumn'
                    ],
                    [
                        'attribute' => 'files',
                        'label' => false,
                        'format' => 'raw',
                        'value' => function($data) {
                            foreach ($data->files as $file) {
                                echo \nemmo\attachments\components\AttachmentsTable::widget(['data' => $data]);
                            }
                        }
                    ],
                    'name',
                    [
                        'attribute' => 'source',
                        'format'    => 'raw',
                        'label'     => 'Source',
                        'value'     => function ($data) {

                            return Html::a(Html::encode($data->source), $data->source_url, ['target' => '_blank']);
                        },
                    ],

I really enjoy your extension. The more I work with the more I find that I can get out of it! Just looking for one more way to extend it. Any help that you can provide will be most appreciated.

Project table prefix not taken into account

Following the basic installation process, my attachments table does not contain the project prefix specified in my main.php:
'tablePrefix' => 'abc_',
The fix is probably simple:

  1. Modify File.php:
    public static function tableName()
    {
    return '{{%attach_file}}';
    }
  2. Fix m150127_040544_add_attachments up() and down() to support tablePrefix

onclick method working only locally

I was trying the suggested method to upload files on form submit but it doesn't seem to work. At least it does not on production server.

When I submit a form locally, even with a rather large file (5MB), the upload is very fast so it completes within milliseconds, even before the form submit.

When I do the same on the production server, which is much slower in bandwidth, the file upload starts but the form is submitted at the same time, so when the file send reaches say 5% the page is changed and upload interrupted.

The upload should probably be handled by returning false to the submit, and attach to file-input's filebatchuploadcomplete event in order to finally submit the form.

I tried this solution:

'onclick' => "function (e) {
    e.preventDefault();
    var element = this;
    $('#file-input').on('filebatchuploadcomplete', function(event, files, extra, element) {
        console.log('File batch upload complete');
        $(element).closest("form").submit();
    });

    $('#file-input').fileinput('upload');
};

But it won't work anyway. The upload seems to complete but it's not attached to the model. More details on the forum

Can't save single upload image

In FileController.php -> actionUpload we can't save single uploaded image. Where ELSE block you must store file name in $result array. Code must like this

if (is_array($model->file)) {
foreach ($model->file as $file) {
$path = $this->getModule()->getUserDirPath() . DIRECTORY_SEPARATOR . $file->name;
$file->saveAs($path);
$result['uploadedFiles'][] = $file->name;
}
} else {
$path = $this->getModule()->getUserDirPath() . DIRECTORY_SEPARATOR . $model->file->name;
$model->file->saveAs($path);
!!!!add this string!!!! --> $result['uploadedFiles'][] = $model->file->name;
}

Upload single file

Hello, thanks for module.
I have a question about uploading single file, how to upload only one file to the model?
How to delete existing(old) file after new file uploaded?
This needed for uploading users avatars

Migrations fail with message class not found

Hi, since your namespace cleanup, the migrations aren't working anymore. I'm not able to solve it, as you are using the getModule function within the migrate to retrieve the table name from the config - do you have an idea how to fix this?

Thanks Philipp

Cannot install thru composer

$ composer.phar require nemmo/yii2-attachments "*"
 ./composer.json has been updated  
Loading composer repositories with package information
Updating dependencies (including require-dev)
Rea                                                           
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package nemmo/yii2-attachments could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

Add image caption, title, alt, and other html attribute support

First, let me congratulate you on an excellent extension. Kartik's File Input widget provides a lot of functionality, but it is somewhat of a pain to set up and use, especially if you have a lot of models that use attachments and you have multiple attachments on each model. Your extension makes all that a breeze.

If you're ever inclined to enhance the extension, I'd like to suggest that you consider a way to add "title" and "alt" for each attachment. Those are important attributes for for attachments (whether they're images or files such as PDFs, etc.). With those enhancements, your extension would really rock!

Stop form submit on error

Thank you very much for this extension. After some hours I managed to get it to work.

When I submit the form and there is an error with the extension, the form just gets submitted anyway. I see in the documentation a deprecated onclick action so I assumed this should work somehow. Is there a setting I've missed?

Add some restrictions to files

It would be great to be able to add some restrictions to the files the user can upload, on a per model basis:

  • Limit the max number of files
  • Limit the mimetype/extension of files
  • Limit the max number of files per mimetype (maybe this is excessive)

Bug file remove bug, see detail below...

Here is the scenario.
The form with 3 fields(reciver, message, attachments) and a submit button.
Step1, fill the reciver and message field.
Step2, add any file and upload it.
Step3, remove the files uploaded in Step2.
Step4, add another files not added in Step2.
Step5, submit the form data.
Here goes the bug, you will find out that the files you delete in Step2 will display in the submit data and the attachments record will insert into the database.

Why? Because the code FileBehavior method saveUploads() will get all the files list in the specified folder. But the files deleted in Step2 still in the folder.

And my own sugesstion is add an event to the remove method. When user remove the file listed in the widgets, removing it from the temp folder at the same time.

Support for prefix on table

At migration and File model is needed to change references of 'attach_file' to '{{%attach_file}}', so that the table prefix can be taken into consideration.

Failed to hide initialPreview

\nemmo\attachments\components\AttachmentsInput::widget([
    //...
    'pluginOptions' => [
        'initialPreview' => false,
    ]
])

I'm going to fix this in my Pull request

Error in execute migration

У вас возникает ошибка при выполнении миграции.
`$ php yii migrate/up --migrationPath=@vendor/nemmo/yii2-attachments/src/migrations
Yii Migration Tool (based on Yii v2.0.11-dev)

Total 1 new migration to be applied:
m150127_040544_add_attachments

Apply the above migration? (yes|no) [no]:y
*** applying m150127_040544_add_attachments
PHP Fatal error: Class 'm150127_040544_add_attachments' not found in /home/debian/sites/avega2.loc/vendor/yiisoft/yii2/console/controllers/MigrateController.php on line 191
PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'm150127_040544_add_attachments' not found'

in /home/debian/sites/avega2.loc/vendor/yiisoft/yii2/console/controllers/MigrateController.php:191

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}`

Предположительно, в файле миграции не нужен namespace.
namespace nemmo\attachments\migrations; стр.3
После его удаления миграция отработала без ошибок.

Configuration of migration

I've never seen something similar before

Apply migrations

	'controllerMap' => [
	...
	'migrate' => [
		'class' => 'yii\console\controllers\MigrateController',
		'migrationNamespaces' => [
			'nemmo\attachments\migrations',
		],
	],
	...
	],

php yii migrate/up

I'm using the advanced template.
Where am I must put this config?

Add flexible configuration of ActionColumn in AttachmentsTableWithPreview

Currently, this widget write ActionColumn [delete] in hardcode
Some times some user not have privileges to delete the file, some time user need to add [download] button in ActionColumn

Sorry, I test upload in frontend, and implement this widget in backend, the link in backend (different location) is incorrect
I don't know I use wrong configuration, but the configuration is same in example

Event afterUpload

Is there an event handler afterUpload? Can I add own code in my project when files are uploaded? For example, email notification.

If not, I'll do it.

Upload image issue

Hello Nemmo, great extension!
On one hand i want to know if there is a method to upload images to my web server in the same order they appear in the preview of multiple file upload scenario. After upload the order get modified. On the other hand i'm experimenting a duplicated image upload issue. The name of the files are the originals but the resulting images get duplicated. Have you got an idea what could be causing this?

Thanks!

AttachmentsInput and AttachmentsTable do not display

I've used nemmo/yii2-attachments successfully for a considerable amount of time. A few days ago, after running composer update, suddenly, <?= \nemmo\attachments\components\AttachmentsTable::widget(['model' => $model]) ?> and

    <?= \nemmo\attachments\components\AttachmentsInput::widget([
        'id' => 'file-input', // Optional
        'model' => $model,
        'options' => [ // Options of the Kartik's FileInput widget
            'multiple' => true, // If you want to allow multiple upload, default to false
        ],
        'pluginOptions' => [ // Plugin options of the Kartik's FileInput widget
            'maxFileCount' => 10 // Client max files
        ]
    ]) ?>

have ceased to display in the input form. There is nothing there. I've checked the page source, and there isn't even any reference to the code for either for these structures in the page source.

Looking at the runtime/log, I find the following embedded in the meswsaging:

Error: Class 'common\modules\healthlog\models\nemmo\attachments\behaviors\FileBehavior' not found in W:\xampp\htdocs\public_html\common\modules\healthlog\models\HealthLogAppointment.php:31

Obviously, somehow, the route to the model the view _form.php is built on has become embedded in the path to the extension. I went back to the declaration of the 'attachments' in common\config\main.php and the declarion of the behavior in the model, and literally copied and pasted each from your instructions. That didn't change anything. Still, noting displays in _form.php for the model.

I suppose I could try more explicitly expressing the path using @Vendor, but I'm hoping you can guide me in an appropriate direction.

Uploading additional file is confusing as existing files disappear

This is what I do:

  1. I add some files and save.
  2. I update the dataset again and add another file.
  3. Existing files disappear. The user will be confused: "Are the files deleted now?", "Do I have to upload all the files again?"
  4. Upon saving one will see that the old files are still there and the additional file is just added as we wanted to.

It is not a big problem, but if there is an easy way to fix this, I would appreciate it very much.

PHP Notice 'yii\base\ErrorException' with message 'Undefined index: file'

Well, no sooner do I resolve one thing, then another crops up. I can upload image and text (pdf, txt) files just fine, but when I attempt to upload a video file (with appropriate mimeTypes in the rules), then I run into this error:

Internal Server Error

PHP Notice 'yii\base\ErrorException' with message 'Undefined index: file' 
in L:\xampp\htdocs\public_html\vendor\nemmo\yii2-attachments\controllers\FileController.php:41
Stack trace:
#0 L:\xampp\htdocs\public_html\vendor\nemmo\yii2-attachments\controllers\FileController.php(41): yii\base\ErrorHandler->handleError(8, 'Undefined index...', 'L:\\xampp\\htdocs...', 41, Array)
#1 [internal function]: nemmo\attachments\controllers\FileController->actionUpload()
#2 L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)
#3 L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#4 L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\Module.php(455): yii\base\Controller->runAction('upload', Array)
#5 L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\web\Application.php(83): yii\base\Module->runAction('attachments/fil...', Array)
#6 L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#7 L:\xampp\htdocs\public_html\backend\web\index.php(18): yii\base\Application->run()
#8 {main}

Just to be sure, this is what I have in my config/main.php modules section:

'attachments' => [
                'class'     => nemmo\attachments\Module::className(),
                'tempPath'  => '@app/uploads/temp',
                'storePath' => '@app/uploads/store',
                'rules'     => [ // Rules according to the FileValidator
                                 'maxFiles'  => 15,
                                 'mimeTypes' =>
                                     'image/gif, image/jpeg, image/png, image/tiff/ image/jpg, text/css,
                                        text/csv, text/html, application/javascript, text/plain, text/rtf, text/xml,
                                        application/vnd.ms-excel, application/json, application/pdf, application/msword,
                                        application/vnd.openxmlformats-officedocument.wordprocessingml.document,
                                        application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, video/mp4,
                                        audio/mpeg3, audio/x-mpeg-3, video/mpeg, video/x-mpeg',
                                 'maxSize'   => 1024 * 1024 * 1024 * 1024
                ]
            ],

Would you be so kind as to point me in the right direction on this? I couldn't find anything particularly helpful in runtime/app.log. I tried deleting and adding the file to upload multiple times, and this is all the Apache log reported:

127.0.0.1 - - [11/Apr/2015:10:58:44 -0500] "GET /attachments/file/download?id=29 HTTP/1.1" 200 31544 "http://larrylutz.lcl/how-to/update?id=21" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
127.0.0.1 - - [11/Apr/2015:10:58:44 -0500] "GET /assets/c62c9d80/config.js?t=F0RD HTTP/1.1" 304 - "http://larrylutz.lcl/how-to/update?id=21" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
127.0.0.1 - - [11/Apr/2015:10:58:44 -0500] "GET /assets/c62c9d80/skins/moono/editor_gecko.css?t=F0RD HTTP/1.1" 304 - "http://larrylutz.lcl/how-to/update?id=21" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
127.0.0.1 - - [11/Apr/2015:10:58:44 -0500] "GET /assets/c62c9d80/lang/en.js?t=F0RD HTTP/1.1" 304 - "http://larrylutz.lcl/how-to/update?id=21" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
127.0.0.1 - - [11/Apr/2015:10:58:44 -0500] "GET /assets/c62c9d80/styles.js?t=F0RD HTTP/1.1" 304 - "http://larrylutz.lcl/how-to/update?id=21" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
127.0.0.1 - - [11/Apr/2015:10:58:44 -0500] "GET /assets/c62c9d80/contents.css?t=F0RD HTTP/1.1" 304 - "http://larrylutz.lcl/how-to/update?id=21" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
127.0.0.1 - - [11/Apr/2015:10:58:51 -0500] "DELETE /attachments/file/delete?id=29 HTTP/1.1" 200 2 "http://larrylutz.lcl/how-to/update?id=21" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
127.0.0.1 - - [11/Apr/2015:10:59:13 -0500] "POST /attachments/file/upload HTTP/1.1" 500 1274 "http://larrylutz.lcl/how-to/update?id=21" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"

So, once again, I'm kind of at a loss on this one.

Problem when using AR in console

If I use the AR in console commands I always get

#0 /home/alex/public_html/cvn/gestione/vendor/yiisoft/yii2/di/ServiceLocator.php(75): yii\base\Component->__get('session')
#1 /home/alex/public_html/cvn/gestione/vendor/nemmo/yii2-attachments/src/Module.php(92): yii\di\ServiceLocator->__get('session')
#2 /home/alex/public_html/cvn/gestione/vendor/nemmo/yii2-attachments/src/behaviors/FileBehavior.php(45): nemmo\attachments\Module->getUserDirPath()
#3 [internal function]: nemmo\attachments\behaviors\FileBehavior->saveUploads(Object(yii\db\AfterSaveEvent))
#4 /home/alex/public_html/cvn/gestione/vendor/yiisoft/yii2/base/Component.php(545): call_user_func(Array, Object(yii\db\AfterSaveEvent))
#5 /home/alex/public_html/cvn/gestione/vendor/yiisoft/yii2/db/BaseActiveRecord.php(964): yii\base\Component->trigger('afterInsert', Object(yii\db\AfterSaveEvent))

no matter if I turn off the behaviour with detach or detach the events.

Files not always linking to correct models

Thank you for the great extension. Sadly, I encountered one quite annoying bug. Here is an example: user uploads some files while creating an Object A, but then decides to cancel the creation of this object (i.e. user just closed the form without pushing "Create" button). This user then decides to create some other Object B with attachment files. After he creates Object B, it will contain not only the files user uploaded while creating Object B, but also files, that were uploaded during the creation of Object A.

I do believe this is happening because temp files directory name is generating from user's current session, so it is not unique for each individual process.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.