cakePHP 3.0 uploading images

前端 未结 6 1283
北荒
北荒 2020-12-16 20:07

I want to upload images in my cakephp 3.0 app. But I get the error message:

Notice (8): Undefined index: Images [APP/Controller/ImagesController.php, line 55         


        
6条回答
  •  有刺的猬
    2020-12-16 20:37

    /*Path to Images folder*/
    $dir = WWW_ROOT . 'img' .DS. 'thumbnail';
    /*Explode the name and ext*/
                    $f = explode('.',$data['image']['name']);
                     $ext = '.'.end($f);
        /*Generate a Name in my case i use ID  & slug*/
                    $filename = strtolower($id."-".$slug);
    
         /*Associate the name to the extension  */
                    $image = $filename.$ext;
    
    
    /*Initialize you object and update you table in my case videos*/
                    $Videos->image = $image;     
                if ($this->Videos->save($Videos)) {
    /*Save image in the thumbnail folders and replace if exist */
                move_uploaded_file($data['image']['tmp_name'],$dir.DS.$filename.'_o'.$ext);
    
                unlink($dir.DS.$filename.'_o'.$ext);
                    } 
    

提交回复
热议问题