上传任何文件cakephp 3

时间:2015-07-08 19:05:38

标签: cakephp-3.0

我只能上传像.jpg和.png这样的文件,我想上传.zip,.psd,.ai等,但是当我尝试收到错误时

  

注意(8):未定义的索引:url [APP / Controller \ MultimediaController.php,第70行]

     

注意(8):未定义的索引:url [APP / Controller \ MultimediaController.php,第71行]

     

注意(8):未定义的索引:url [APP / Controller \ MultimediaController.php,第72行]

     

注意(8):未定义的索引:url [APP / Controller \ MultimediaController.php,第75行]

     

注意(8):未定义的索引:url [APP / Controller \ MultimediaController.php,第81行]

我的MultimediaControler:

    public function add()
{
    $multimedia = $this->Multimedia->newEntity();
    if ($this->request->is('post')) {
        $multimedia = $this->Multimedia->patchEntity($multimedia, $this->request->data);

          // Saving the file
        $file = $_FILES['url']; //Line 70
        $path = "webroot\\files\\" .$_FILES['url']['name'];   //Line 71
        $success = move_uploaded_file($_FILES['url']['tmp_name'], $path);  //Line 72


        $filename = $_FILES['url']['name'];  //Line 75

        $created = $_SESSION['Auth']['User']['id'];

        $type = mime_content_type($path);

        $size =  $_FILES['url']['size'];   //Line 81

        $multimedia->set('mime_type', $type);
        $multimedia->set('url', $filename);
        $multimedia->set('filename', $filename);
        $multimedia->set('size', $size);
        $multimedia->set('created_by', $created);



        if ($this->Multimedia->save($multimedia)) {
            $this->Flash->success('The multimedia has been saved.');
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error('The multimedia could not be saved. Please, try again.');
        }
    }
    $languages = $this->Multimedia->Languages->find('list', ['limit' => 200]);
    $categories = $this->Multimedia->Categories->find('list', ['limit' => 200]);
    $users = $this->Multimedia->Users->find('list', ['limit' => 200]);
    $this->set(compact('multimedia', 'languages', 'categories', 'users'));
    $this->set('_serialize', ['multimedia']);
}

更新

如果我尝试上传psd文件并打印$ multimedia,我会得到:

  

{“mime_type”:“directory”,“url”:null,“filename”:null,“size”:null,“created_by”:3}

但如果我上传jpg或png,我会获得所有数据

0 个答案:

没有答案