milesj / uploader

[Deprecated] A CakePHP plugin for file uploading and validating.
MIT License
193 stars 73 forks source link

File Ext changes when file is uploaded #109

Closed 010100 closed 11 years ago

010100 commented 11 years ago

Hello first I should give you thanks for this plug in, well now going to the issue I have problem when I upload files, the uploader damage all the files and rename the file ext to .txt.

for example if upload "08102012009.jpg" the result is: "/files/docs/08102012009.txt" My configuration:

Model

    public $actsAs = array(
    'Uploader.Attachment' => array(
            'document' => array(
                    'tempDir' => '/tmp/',
                    'uploadDir' => '/var/www/cch/app/webroot/files/docs/',
                    'finalPath' => '/files/docs/',
                    'dbColumn' => 'document_path'
            )
    ),
    'Uploader.FileValidation' => array(
                'img' => array(
                    'extension' => array('jpg', 'png', 'jpeg','pdf','x-pdf','octet-stream'),
                    'required'  => true
                )
        )
    );

In the edit.cpt view

                    echo $this->JqueryValidation->input("Edocument.volume", array(  'placeholder' => __('Volume'),$
                    echo $this->JqueryValidation->input("Edocument.number", array(  'placeholder' => __('Number'),$
                    echo $this->JqueryValidation->input("Edocument.locked", array(  'placeholder' => __('Locked'),$
                    echo $this->Form->input('document', array('type' => 'file'));

        echo $this->Form->button( __( 'Save') , array( 'type' => 'submit', 'class' => 'btn btn-primary' ) );

        echo $this->Form->button( __( 'Clear') , array( 'type' => 'reset', 'class' => 'btn' ) );
    echo $this->Form->end();

And If you wonder for the others files

root@Server-01:/var/www/cch/app# dir Plugin/ Acl BootstrapCake Composer DebugKit Forum Uploader Utility root@Server-01:/var/www/cch/app# dir Plugin/Uploader/ composer.json license.md Locale milesj-Uploader-ca0250a Model readme.md version.md root@Server-01:/var/www/cch/app# dir Vendor/ autoload.php aws composer guzzle mjohnson symfony titon root@Server-01:/var/www/cch/app# dir Vendor/mjohnson/ decoda transit

Thanks

milesj commented 11 years ago

Can you do a quick test outside of the Uploader and see what fileinfo returns for the mimetype of that image? http://www.php.net/manual/en/function.finfo-file.php

010100 commented 11 years ago

The MIME type for your file is: image/jpeg

That's the output

010100 commented 11 years ago

I used http://mime.ritey.com/ to determine the mime types before, is weird because I check it in cakephp 2.3.1 both windows and linux, and is the same result.

010100 commented 11 years ago

Those files are the ones of cake if you ask for another configuration. http://tinyurl.com/ca4uzzr

Thanks for takeing time to see and answer :+1: :)

milesj commented 11 years ago

I don't see anything wrong with your code. Can you send me the images also? I'll try testing with them.

It may be an environment issue, either PHP itself or Apache/nginx.

010100 commented 11 years ago

Ok in the same medaifire folder I have the files used for test (3 images & 1 pdf file). Salute

010100 commented 11 years ago

Tested on: XAMPP with PHP Version 5.4.7 & mysqlnd 5.0.10 - 20111026 OS Windows Apache/2.2.22 (Ubuntu) PHP 5.5.29 OS: Linux Ubuntu 12.04.1

In addition I found this content in one of the uploaded images, is something related to the plugin?

_method=PUT&data%5BEdocument%5D%5Btitle%5D=Title&data%5BEdocument%5D%5Babstract%5D=This&data%5BEdocument%5D%5Bjournal_id%5D=1&data%5BEdocument%5D%5Bsubject_id%5D=1&data%5BEdocument%5D%5Bdocument_type_id%5D=1&data%5BEdocument%5D%5Bcongress_id%5D=2&data%5BEdocument%5D%5Bdocument_date%5D=2013-03-15&data%5BEdocument%5D%5Bfirst_page%5D=12&data%5BEdocument%5D%5Blast_page%5D=12&data%5BEdocument%5D%5Bvolume%5D=23&data%5BEdocument%5D%5Bnumber%5D=33&data%5BEdocument%5D%5Blocked%5D=0&data%5BEdocument%5D%5Bimage%5D=Finland.jpg&data%5BAuthor%5D%5BAuthor%5D=&data%5BAuthor%5D%5BAuthor%5D%5B%5D=3&data%5BAuthor%5D%5BAuthor%5D%5B%5D=5&data%5BAuthor%5D%5BAuthor%5D%5B%5D=7&data%5BUser%5D%5BUser%5D=&data%5BKeyword%5D%5BKeyword%5D=&data%5BKeyword%5D%5BKeyword%5D%5B%5D=1&data%5BKeyword%5D%5BKeyword%5D%5B%5D=2&data%5BKeyword%5D%5BKeyword%5D%5B%5D=31&data%5BKeyword%5D%5BKeyword%5D%5B%5D=54&data%5BKeyword%5D%5BKeyword%5D%5B%5D=55&data%5BKeyword%5D%5BKeyword%5D%5B%5D=56&data%5BKeyword%5D%5BKeyword%5D%5B%5D=58&data%5BKeyword%5D%5BKeyword%5D%5B%5D=60

010100 commented 11 years ago

Finally I found the answer, in the form I use a jquery validation in several field so in this case just need to add another type but in the beginning of the form ('type'=>'file').

   .... Some code
    echo $this->Form->create( 'Edocument', array('class' => 'jquery-validation', 'type' => 'file')  );
        echo $this->JqueryValidation->input("Edocument.title", array(  'placeholder' => __('Title'), 'label' => __('Title') ));
        echo $this->JqueryValidation->input("Edocument.abstract", array(  'placeholder' => __('Abstract'), 'label' => __('Abstract') ));
        echo $this->JqueryValidation->input("Edocument.journal_id", array(  'placeholder' => __('Journal Id'), 'label' => __('Journal'), 'options' => $journals, 'empty' => true ));
        echo $this->JqueryValidation->input("Edocument.subject_id", array(  'placeholder' => __('Subject Id'), 'label' => __('Subject'), 'options' => $subjects, 'empty' => true ));
        echo $this->JqueryValidation->input("Edocument.document_type_id", array(  'placeholder' => __('Document Type Id'), 'label' => __('Document Type'), 'options' => $documentTypes, 'empty' => true ));
        echo $this->JqueryValidation->input("Edocument.congress_id", array(  'placeholder' => __('Congress Id'), 'label' => __('Congress'), 'options' => $congresses, 'empty' => true ));
        echo $this->JqueryValidation->input("Edocument.document_date", array(  'placeholder' => __('Document Date'), 'label' => __('Document Date'), 'type' => 'text', 'class' => 'datepicker2' ));
        echo $this->JqueryValidation->input("Edocument.first_page", array(  'placeholder' => __('First Page'), 'label' => __('First Page') ));
        echo $this->JqueryValidation->input("Edocument.last_page", array(  'placeholder' => __('Last Page'), 'label' => __('Last Page') ));         
        echo $this->JqueryValidation->input("Edocument.volume", array(  'placeholder' => __('Volume'), 'label' => __('Volume') ));
        echo $this->JqueryValidation->input("Edocument.number", array(  'placeholder' => __('Number'), 'label' => __('Number') ));
        echo $this->JqueryValidation->input("Edocument.locked", array(  'placeholder' => __('Locked'), 'label' => __('Locked') ));
        echo $this->Form->input('image', array('type' => 'file'));

   .... Buttons code and so on.
milesj commented 11 years ago

Yeah that would do it. Nice catch!