为什么我的图片无法上传?

时间:2012-02-01 23:37:27

标签: image magento configuration upload backend

我正在尝试将一个工作图像上传字段添加到我的新Magento配置部分,但它无法正常工作。每当我“上传”一个文件(选择一个文件,然后保存配置)时,后端模型函数_beforeSave()(我可能是错误的,位于app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php)没有被调用,文件也没有上传。有什么想法吗?

我在本地代码池中使用名为Page的模块。这会导致问题吗?我不需要这样称呼,为什么它被称为“页面”是一个很长的故事。

的System.Xml:

<?xml version="1.0" ?>
<config>
  <sections>
    <newtheme module="page" translate="label">
      <label>Newtheme</label>
      <sort_order>200</sort_order>
      <show_in_default>1</show_in_default>
      <show_in_website>1</show_in_website>
      <show_in_store>1</show_in_store>
      <tab>general</tab>
      <groups>
        <homepage translate="label">
          <label>Home Page</label>
          <comment>Some comment about my group</comment>
          <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>
          <fields>
            <banner_image translate="label tooltip comment">
              <label>Image upload</label>
              <comment>This is an image field</comment>
              <tooltip>Image tooltip!</tooltip>
              <show_in_default>1</show_in_default>
              <show_in_website>1</show_in_website>
              <show_in_store>1</show_in_store>
              <sort_order>200</sort_order>
              <frontend_type>image</frontend_type>
              <backend_model>adminhtml/system_config_backend_image</backend_model>
              <upload_dir config="system/filesystem/media" scope_info="1">newtheme/homepage</upload_dir>
              <base_url type="media" scope_info="1">newtheme/homepage</base_url>
            </banner_image>
          </fields>
        </homepage>
      </groups>
    </newtheme>
  </sections>
</config>

我也有一个adminhtml.xml,但是猜它有效,因为我可以打开这个部分。

使用Firefox的Live HTTP Headers(我使用Mac)获取标题,将POST发送到以下网址:http://example.com/index.php/admin/system_config/save/section/newtheme/key/84670cdcd055b925312eb3ecf0cb98e1/

POST /index.php/admin/system_config/save/section/newtheme/key/84670cdcd055b925312eb3ecf0cb98e1/ HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: nl,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://example.com/index.php/admin/system_config/edit/section/newtheme/key/eba46a991cc50c762cdac658da954c8a/
Cookie: adminhtml=23f1b26aa83ff7208b47b350794616f9
Content-Type: multipart/form-data; boundary=---------------------------9849436581144108930470211272
Content-Length: 97451
-----------------------------9849436581144108930470211272
Content-Disposition: form-data; name="form_key"

2vTBh14zpv3FCEAV
-----------------------------9849436581144108930470211272
Content-Disposition: form-data; name="config_state[newtheme_homepage]"

1
-----------------------------9849436581144108930470211272
Content-Disposition: form-data; name="groups[homepage][fields][mycustom_field][value]"

jkflsjfgkld
-----------------------------9849436581144108930470211272
Content-Disposition: form-data; name="groups[homepage][fields][image_field][value]"; filename="sub_banner_3.png"
Content-Type: image/png

PNG


HTTP/1.1 302 Found
Date: Thu, 02 Feb 2012 07:57:07 GMT
Server: Apache/2
X-Powered-By: PHP/5.2.17
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: adminhtml=23f1b26aa83ff7208b47b350794616f9; expires=Sat, 04-Feb-2012 07:57:08 GMT; path=/; domain=example.com; httponly
Location: http://example.com/index.php/admin/system_config/edit/section/newtheme/key/eba46a991cc50c762cdac658da954c8a/
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=1, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

我猜文件正在发送。那么为什么不被保存?是不是正确的后端模型?

1 个答案:

答案 0 :(得分:0)

您好请遵循此 检查config.xml中是否包含帮助程序,否则添加以下帮助程序块

<helpers><newtheme><class>NAMESPACE_Newtheme_Helper</class></newtheme></helpers>

并且还要检查你使用的模块名称是否区分大小写,因为在linux中有新主题和Newtheme的区别 同时检查文件夹是否在媒体newtheme / homepage中创建 清除缓存和会话然后检查,在检查上述内容后告诉我它是否有效