回答
後研究了幾天,這裏是一個易於使用的例子如何在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. Prestashop - 圖像上傳/管理選項管理這些圖像
- 2. 在Zend Framework中管理圖像上傳
- 3. 圖像上傳管理在php
- 4. Magento的 - 管理多圖像和
- 5. Django管理圖像/文檔上傳/管理
- 6. Magento自定義模塊圖像恢復
- 7. 如何從管理面板上傳magento 1.9.2版本中的自定義圖像
- 8. 在Bassi橫幅滑塊圖像不上傳在magento中?
- 9. ImportError管理模塊
- 10. 圖像上傳時註冊Magento
- 11. Magento產品csv與圖像上傳
- 12. 上傳圖像在magento前端
- 13. 如何在CakePHP中處理圖像管理(上傳,刪除等)?
- 14. 使用AdSence實現廣告上傳管理模塊實施
- 15. 與Magento的管理頁面中的自定義模塊中創建管理模塊
- 16. 試圖上傳圖像到威盛內容管理API JAVA
- 17. magento管理塊未被創建
- 18. Jmeter處理圖像上傳
- 19. 圖像管理
- 20. 模擬圖像上傳視圖模型
- 21. Magento的自定義模塊管理權限
- 22. Magento模塊與前端和管理功能
- 23. Magento:自定義模塊:如何管理多個表
- 24. Magento自定義管理模塊404找不到
- 25. 的Magento的Hello World管理模塊返回404
- 26. Magento刪除(顯示/隱藏編輯器)按鈕管理模塊
- 27. 爲新的管理模塊配置Magento佈局
- 28. Magento Inactive模塊仍然出現在管理員
- 29. 在magento後端翻譯自定義模塊管理面板
- 30. Magento的,我怎麼能覆蓋管理模塊正確
只是美好的,拯救了我的一天 – 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