我正在開發一個應用程序,其中創建了一個具有以下屬性的products
表。無法使用Miles Johnson上傳器上傳圖像
{id, image, warranty-image, created, modified}
我使用miles johnson 4.3.1 uploader
上傳圖片。所以我寫了如下$actsAs
Product 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
圖像。請幫我解決問題。這項工作將更受讚賞。
所以是否_uploading_只選擇'image'文件,或者你實際上意味着它只是_storing_只選擇'image',即文件它實際上是_uploading_這兩個文件(瀏覽器發送這兩個文件的數據),但是爲'warrant_image'選擇的文件沒有存儲在數據庫和/或文件系統中? – ndm
@ndm它只上傳'圖像'文件並複製到'表'中,但不會發生在'warranty_image'上。 – Sanganabasu
因此,如果真的如此,那麼生成的HTML表單代碼和發送的請求(在您的控制器中檢查'debug($ this-> request-> data)')看起來像什麼? – ndm