milesj / uploader

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

Uploaded files contain the HTTP PUT request, not file data #178

Closed cait08 closed 10 years ago

cait08 commented 10 years ago

First: I've installed the plugin per the documentation, installing the most recent 4.x version via Composer, and including Composer in core.php.

I'm trying to add user profile pictures to my Users model, so I added the following to my User model:

    'Uploader.Attachment' => array(
        'image' => array(
            'tempDir' => TMP,
            'uploadDir' => '/home/public/app/webroot/img/uploads/',
            'finalPath' => '/img/uploads/',
            'overwrite' => true
        ),
    'Uploader.FileValidation' => array(
        'image' => array(
            'extension' => array('gif', 'jpg', 'png', 'jpeg'),
            'type' => 'image',
        )
    )
    )

And my form (leaving out the user text fields like email)

    echo $this->Form->create('User', array('role' => 'form'), array('type' => 'file'));
    echo $this->Form->input('image', array('type' => 'file'));
    echo $this->Form->submit('Submit', array('class' => 'btn btn-large btn-primary'));
    echo $this->Form->end();

This gives me an upload field. However, when I upload an image, it doesn't upload: The saved file just contains the HTTP PUT request with the filename, for example

_method=PUT&data%5BUser%5D%5Bimage%5D=icon2.png

Why would this be happening? AFAIK I've followed the directions exactly.

cait08 commented 10 years ago

Found the solution:

echo $this->Form->create('User', array('role' => 'form'), array('type' => 'file')); should be

echo $this->Form->create('User', array('role' => 'form', 'type' => 'file'));

designvoid commented 10 years ago

I am intermittantly having this very problem also - sometimes the uploader works aok, other times the uploaded documents are either corrupt or contain the post array... I am completely at a loss as to why and now have the job of repairing a few thousand uploads... anyone able to shed any light?

milesj commented 10 years ago

What version of Cake are you using? Maybe there was a recent change?

designvoid commented 10 years ago

CAKE_VERSION 2.4.4 Php Version 5.4.22 Uploader version 4.5.2

designvoid commented 10 years ago

I have just updated to latest Uploader plugin.