2013-10-28 45 views
0

我正在開發一個應用程序,其中創建了一個具有以下屬性的products表。無法使用Miles Johnson上傳器上傳圖像

{id, image, warranty-image, created, modified} 

我使用miles johnson 4.3.1 uploader上傳圖片。所以我寫了如下$actsAsProduct model

public $actsAs = array(
    'Uploader.Attachment' => array(
     'image' => array(
      'overwrite' => true, 
      'uploadDir' => 'img/products', 
      'finalPath' => '', 
      'dbColumn' => 'image', 
      'transforms' => array(
       'imageLarge' => array(
        'nameCallback' => 'transformNameCallback', 
        'method' => 'resize', 
        'prepend' => 'large_', 
        'width' => 750, 
        'height' => 100, 
        'aspect' => false 
       ) 
     ), 
     'warranty_image' => array(
      'overwrite' => true, 
      'uploadDir' => 'img/products', 
      'finalPath' => '', 
      'dbColumn' => 'warranty_image', 
      'transforms' => array(
       'warranty_imageSmall' => array(
        'nameCallback' => 'transformNameCallback', 
        'method' => 'resize', 
        'prepend' => 'small_', 
        'width' => 150, 
        'height' => 96, 
        'aspect' => false 
       ) 
      ) 
     ) 
    ), 
    'Uploader.FileValidation' => array(
     'image' => array(
      'required' => true, 
      'extension' => array('gif', 'jpg', 'png', 'jpeg'), 
      'type' => array('image'), 
      'minWidth' => 100, 
      'minHeight' => 100, 
      'filesize' => 5242880 
     ), 
     'warranty_image' => array(
      'required' => true, 
      'extension' => array('gif', 'jpg', 'png', 'jpeg'), 
      'type' => 'image', 
      'minWidth' => 100, 
      'minHeight' => 96, 
      'filesize' => 5242880 
     ) 
    ) 
); 

public function transformNameCallback($name, $file) { 
    return $this->getUploadedFile()->name(); 
} 

add view我寫file inputs如下。

echo $this->Form->create('Product', array('enctype' => 'multipart/form-data')); 
echo $this->Form->file('image'); 
echo $this->Form->file('warranty_image'); 
echo $this->Form->end(); 

這只是上傳只上傳圖片image但不warranty_image圖像。請幫我解決問題。這項工作將更受讚賞。

+0

所以是否_uploading_只選擇'image'文件,或者你實際上意味着它只是_storing_只選擇'image',即文件它實際上是_uploading_這兩個文件(瀏覽器發送這兩個文件的數據),但是爲'warrant_image'選擇的文件沒有存儲在數據庫和/或文件系統中? – ndm

+0

@ndm它只上傳'圖像'文件並複製到'表'中,但不會發生在'warranty_image'上。 – Sanganabasu

+0

因此,如果真的如此,那麼生成的HTML表單代碼和發送的請求(在您的控制器中檢查'debug($ this-> request-> data)')看起來像什麼? – ndm

回答

0

在視圖或CakePHP表單助手輸入標記中使用HTML輸入標記。

echo $this->Form->input('image', array('type' => 'file', 'required' => false, 'label' => 'Select the File to Upload')); 
echo $this->Form->input('warranty_image', array('type' => 'file', 'required' => false, 'label' => 'Select the File to Upload')); 
0

您的數據庫表格使用「warranty-image」作爲字段。

但您的PHP代碼使用「warranty_image」。

注意「 - 」而不是「_」