2010-02-09 46 views
0

使用CakePHP文件上載cakephp的

$這 - 上傳到服務器上的圖像時>模型 - > Behaviors->連接( 'ImageUpload',配置::讀( 'photo.files'));

照片上傳成功,和數據庫中的字段也

但顯示以下錯誤而不是返回到索引頁。


通知(8):未定義指數:類[CORE \蛋糕\庫\模型\行爲\ upload.php的,線104]

通知(8):未定義指數:類[CORE \ (輸出在E:\ umoorthy_105act10 \ projects \ dev1base \ core \ cake \目錄中已經發送),但不能修改標題信息 - 不能修改標題信息 - basics.php:111)[CORE \ cake \ libs \ controller \ controller.php,line 614]


wat做什麼?

+0

什麼行爲,你實際使用?如果是MeioUpload,這個鏈接可能會有所幫助: http://www.mail-archive.com/[email protected]/msg76460.html – harpax 2010-02-09 15:28:56

+0

即時通訊使用圖片上傳行爲.. – udhaya 2010-02-09 15:42:00

+0

任何指向該特定行爲的鏈接?粗略的Google搜索沒有提供任何有用的信息。 – deceze 2010-02-10 01:08:04

回答

0

蛋糕已經寫在哪裏尋找問題

Configure::read('photo.files') 

做以下檢查,如果一切正常

pr(Configure::read('photo.files')) 
0
public function uploadFilesIphone($folder, $formdata, $replace , $itemId = null) { 
       // setup dir names absolute and relative echo "<pre>";  print_r($formdata);  exit; 

      $folder_url = WWW_ROOT.$folder; 
      $rel_url = $folder; //echo 

       // create the folder if it does not exist 
       if(!is_dir($folder_url)) { 
        mkdir($folder_url); 
       } 

       // if itemId is set create an item folder 
       if($itemId) { 
        // set new absolute folder 
        $folder_url = WWW_ROOT.$folder.'/'.$itemId; 
        // set new relative folder 
        $rel_url = $folder.'/'.$itemId; 
        // create directory 
        if(!is_dir($folder_url)) { 
         mkdir($folder_url); 
        } 
       } 

       // list of permitted file types, this is only images but documents can be added 
       $permitted = array('image/gif','image/jpeg','image/pjpeg','image/png','application/octet-stream'); 

       // loop through and deal with the files; 

       $key = array(); 
       $value = array(); 
       foreach($formdata as $key => $value) 
       { 
        if($key == is_array($value)) 
        { 
         $filename = str_replace(".", $replace , $value['name']); 
        } 

        // replace spaces with underscores 

        // assume filetype is false 
        $typeOK = false; 
        // check filetype is ok 

        foreach($permitted as $type) 
        { 
         if($key == is_array($value)) 
         { 
          if($type == $value['type']) 
          { 
           $typeOK = true; 
           break; 
          } 
         } 
        } 
        // if file type ok upload the file 

        if($typeOK) { 
         // switch based on error code 
         if($key == is_array($value)) 
         { 
          switch($value['error']) 
          { 
          case 0: 
           // check filename already exists 
           if(!file_exists($folder_url.'/'.$filename)) 
           { 
            // create full filename 
            $full_url = $folder_url.'/'.$filename; 
            $url = $rel_url.'/'.$filename; 

            // upload the file 
            if($key == is_array($value)) 
            { 
             $success = move_uploaded_file($value['tmp_name'], $url); 
            } 
           } 
           else 
           { 
            // create unique filename and upload file 
            // ini_set('date.timezone', 'Europe/London'); 
            $now = date('Y-m-d-His'); 
            $full_url = $folder_url.'/'.$now.$filename; 
            $url = $rel_url.'/'.$now.$filename; 
            if($key == is_array($value)) 
            { 
             $success = move_uploaded_file($value['tmp_name'], $url); 
            } 
           } 
           // if upload was successful 
           if($success) 
           { 
            // save the url of the file 
            $result['urls'][] = $url; 
           } 
           else 
           { 
            $result['errors'][] = "Error uploaded $filename. Please try again."; 
           } 
           break; 
          case 3: 
           // an error occured 
           $result['errors'][] = "Error uploading $filename. Please try again."; 
           break; 
          default: 
           // an error occured 
           $result['errors'][] = "System error uploading $filename. Contact webmaster."; 
           break; 
         } 
        } 
        elseif($value['error'] == 4) 
        { 
         // no file was selected for upload 
         $result['nofiles'][] = "No file Selected"; 
        } 
        else 
        { 
         // unacceptable file type 
         $result['errors'][] = "$filename cannot be uploaded. Acceptable file types: gif, jpg, png."; 
        } 
        } 
       } 
      return $result; 
      }