回答
後研究了幾天,這裏是一個易於使用的例子如何在Magento的 How to create an image or video uploader for the Magento Admin Panel上傳文件
Bassically,我們需要將'enctype' => 'multipart/form-data'
添加到我們的形式
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save'),
'method' => 'post',
'enctype' => 'multipart/form-data'
)
);
file
類型的字段添加到我們的字段集
$fieldset->addField('fileinputname', 'file', array(
'label' => 'File label',
'required' => false,
'name' => 'fileinputname',
));
並將其保存在我們的控制器
if(isset($_FILES['fileinputname']['name']) and (file_exists($_FILES['fileinputname']['tmp_name']))) {
try {
$uploader = new Varien_File_Uploader('fileinputname');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$path = Mage::getBaseDir('media') . DS ;
$uploader->save($path, $_FILES['fileinputname']['name']);
$data['fileinputname'] = $_FILES['fileinputname']['name'];
}catch(Exception $e) {
}
}
這需要進入你的模塊的etc/system.xml
文件:
<?xml version="1.0"?>
<config>
<sections>
<imagesection> <!-- Make up a section key (configuration sidebar) -->
<!-- ... -->
<groups>
<imagegroup> <!-- Make up a group key (the part you can expand/collapse) -->
<!-- ... -->
<fields>
<imagefield> <!-- Make up a field key -->
<label>Field Name</label>
<frontend_type>image</frontend_type>
<backend_model>adminhtml/system_config_backend_image</backend_model>
<upload_dir config="system/filesystem/media" scope_info="1">uploaddir</upload_dir> <!-- would upload into media/uploaddir -->
<base_url type="media" scope_info="1">uploaddir</base_url> <!-- same as previous line -->
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</imagefield>
我們如何可以調整與上面的代碼的形象? – liyakat 2013-08-22 13:01:49
這個問題太舊了,我甚至都不記得這段代碼是幹什麼的。我建議你創建一個新的問題。 – mattalxndr 2013-08-22 13:20:41
你忘了編碼? :( – liyakat 2013-08-23 04:04:19
- 1. Magento上傳模塊
- 2. Magento自定義管理模塊與圖像文件
- 3. Prestashop - 圖像上傳/管理選項管理這些圖像
- 4. magento自定義模塊,上傳多個圖像
- 5. 如何在自定義模塊中上傳圖片,就像在magento的管理員中添加產品一樣?
- 6. 在Zend Framework中管理圖像上傳
- 7. 圖像上傳管理在php
- 8. Carrierwave + Mongoid + gridfs + Padrino管理圖像上傳
- 9. 文件上傳不能在Magento中使用自定義管理模塊
- 10. Magento在自定義管理模塊網格上顯示404
- 11. Django管理圖像/文檔上傳/管理
- 12. Magento的 - 管理多圖像和
- 13. Magento自定義模塊圖像恢復
- 14. 如何從管理面板上傳magento 1.9.2版本中的自定義圖像
- 15. 試圖顯示自定義模塊在管理網格圖像
- 16. Magento - 無法上傳管理產品圖片
- 17. Magento:圖片上傳時出錯,回覆:管理員登錄表
- 18. Magento管理 - 徽標文本字段更改爲上傳圖片
- 19. 在Bassi橫幅滑塊圖像不上傳在magento中?
- 20. 上傳每行更多的圖像在Magento靜態塊
- 21. ImportError管理模塊
- 22. Magento的模塊默認的圖片上傳位置
- 23. 如何在CakePHP中處理圖像管理(上傳,刪除等)?
- 24. 使用AdSence實現廣告上傳管理模塊實施
- 25. Magento產品csv與圖像上傳
- 26. 圖像上傳時註冊Magento
- 27. 上傳圖像在magento前端
- 28. 與Magento的管理頁面中的自定義模塊中創建管理模塊
- 29. magento管理員重定向到模塊主模塊後的主頁
- 30. 試圖上傳圖像到威盛內容管理API JAVA
只是美好的,拯救了我的一天 – Yaroslav 2012-11-15 15:34:23
要麼我在那個上做錯了什麼,要麼它不適用於1.4。 – Mike 2013-05-17 17:20:51
這是在1.9上進行測試的,但是你可以試試用1.6發佈的CE。 – 2013-07-29 13:00:34