尝试使用milesjohnson的上传插件上传zip / rar文件时出现问题

时间:2011-06-06 05:47:59

标签: cakephp plugins

我是cakephp的新手,我找到了milesjohnson's upload plugin, 我有点喜欢它,主要是因为它让我有机会在上传后重命名文件。遗憾的是,我无法上传任何zip / rar文件。

这是我上传文件的操作:

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'));
    }

这是我每次尝试上传任何zip / rar文件时出现的错误:enter image description here

修改

完整插入查询:

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') 

有没有人对问题可能有什么想法?

提前致谢。

3 个答案:

答案 0 :(得分:0)

我认为你所编写的代码没有任何内容,但你应该查看插件,看看它是否允许你上传zip。

你的插件中有条件你只能上传某些文件,比如jpg,png,txt等。

我希望能帮助你。

此致 Archit

答案 1 :(得分:0)

您是否完全确定表单上的文件输入是否已指定type =>文件,并且您的表单是否相同?

另外我会看看其他上传者 - MeioUpload可以允许重命名等等,并且有点更新。您还可以在github上找到Cuploadify插件(uploadify for cake)。

答案 2 :(得分:0)

确保您的表单设置为

multipart/form-data
,如下所示:

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

以下代码将上传文件:

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!'));   

     }
}
相关问题