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

发布于 2025-01-01 17:02:14 字数 4615 浏览 2 评论 0原文

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

我在本地代码池中我自己的命名空间中使用一个名为 Page 的模块。这会引起问题吗?我不需要这么称呼它,而为什么它被称为“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 的实时 HTTP 标头(我使用 Mac)将标头发送到以下网址: 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

我猜文件发送正常。那么为什么没有被保存呢?是后端模型调用方式不正确吗?

I'm trying to add a working image upload field to my new Magento configuration section, but it isn't working. Whenever I "upload" a file (pick a file, then save the config), the backend model function _beforeSave() (which I, possibly by error, located in app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php) isn't being called and the file isn't uploaded either. Any thoughts?

I'm using a module called Page in my own namespace in the local code pool. Is this causing problems? I don't need to call it that, and why it's called "Page" is a long story.

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>

I also have an adminhtml.xml, but guess it works, because I can open the section just fine.

Got the headers using Firefox' Live HTTP Headers (I use a Mac) for the POST to the following url: 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

I guess the file is being sent alright. So why isn't is saved? Is it the backend model that isn't called the right way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任谁 2025-01-08 17:02:14

您好,请关注此
检查 config.xml 中是否包含 helpers,否则添加到 helpers 块下面

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

并且还要检查您使用的模块名称是否在各处区分大小写,如在 linux 中 newtheme 和 Newtheme 存在差异
另请检查该文件夹是否在 media newtheme/homepage 中创建
清除缓存和会话,然后检查,检查上述内容后让我知道它是否有效

Hello Please follow this
Check if helpers is included in config.xml else add below helpers block

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

And Also check if the module name you are using is case sensitive everywhere as in linux there is difference in newtheme and Newtheme
Also check if the folder is created in media newtheme/homepage
Clear the cache and session and then check, let me know if it works after checking above things

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文