开发者

Problem when trying to upload zip/rar files with the milesjohnson's upload plugin

I'm new to cakephp and I have found this milesjohnson's upload plugin , and I kind of like it, mostly because it gives me the chance of renaming the file once uploaded.Unfortunately, I can't get it to upload any zip/rar files.

This is the ac开发者_Python百科tion where I upload the file:

function add() {
        if (!empty($this->data)) {

            if ($data = $this->Uploader->upload('link_referencia', array('name' => date("dmYhis")))) {
                 debug($data);
                 $this->data['Publicacione']['link_referencia']=$data['name'];
            }
            $this->Publicacione->create();

            if ($this->Publicacione->save($this->data)) {
                $this->Session->setFlash(__('The publicacione has been saved', true));
                //$this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The publicacione could not be saved. Please, try again.', true));
            }
        }
        $users = $this->Publicacione->User->find('list');
        $this->set(compact('users'));
    }

And this is the error I get everytime I attempt to upload any zip/rar file :

Problem when trying to upload zip/rar files with the milesjohnson's upload plugin

EDIT

Full insert query:

INSERT INTO `publicaciones` (`vigencia`, `tipo`, `titulo`, `descripcion`, `fecha_publicacion`, `fecha_caducidad`, `link_referencia`, `modified`, `created`) VALUES (1, 'c', 'there\'s nothing you can\'t do', '
fsdfsdfsdf
', '2011-06-07', '2011-06-30', Array, '2011-06-07 16:47:23', '2011-06-07 16:47:23') 

Does anyone have any ideas on what the problem might be?

Thanks in advance.


i think there is nothing with the code what you have written but you should look at in to the plugin and find out whether it gives permission you to upload zip or not.

there will be conditions in your pluggin that you can upload only some kind of files like jpg,png,txt something like that.

I hope that helps you.

Regards, Archit


Are you totally sure your File input on the form has type=>file specified, and same for your form?

Also I would look at other uploaders - MeioUpload can allow renaming and so on and is a bit more up to date. There is also the Cuploadify plugin (uploadify for cake) you can find on github.


Make sure your form is set to

multipart/form-data
like so:

<?php echo $this->Form->create('File', array('enctype' => 'multipart/form-data')); ?>

The following code will upload a file:

if ($this->request->is('post')) {


    if ( $this->data['File']['file']['error'] <= 0  && $this->data['File']['file']['size'] <=   8388608 ) { // Check for no errors and that File size is around 8mb.

    $folder = new Folder (ROOT . DS . 'app' . DS . 'filestorage' . DS, true);  // create folder in /app/filestorage/

    $path = $folder->path . $this->data['File']['file']['name']; // Set path to newly created folder + uploaded file name.

    $tmpUrl = new File ( $this->data['File']['file']['tmp_name'] ); // Create temporary file object

    if ($tmpUrl->copy($path , true) ) { // If copying file to path is successful,

        $this->Session->setFlash(__('File uploaded succesfully!'));   

     }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜