如何让magento 增加更多的附件文件类型

  • A+
所属分类:高级设置 插件使用

有时,我们要上传.rar, .zip等文件附件,方法如下:

第一种方法,直接改动核心

How to Allow more file types Magento

Allow more file types to Magento.

I wanted to add a PDF file to the product description but Magento just allow image file types.

Let’s get started.

Core Files

Look for the file: /app/code/Core/Mage/Cms/etc/config.xml

You should create the same folder structure inside /app/local/…

That’s the way to make the change upgrade proof. But I did and didn’t work :(

Add the extensions

Open the config.xml I mentioned above and around the line 100 you will find something like this:

Please notice I added <pdf>1</pdf> to the allowed extensions.

After uploading the file refresh the Magento Cache and also try to log out from the Magento Admin panel.

 

第二种方法,基本同上,就是使用自己的扩展

Magento: Allow Other File Types in Wysiwyg Editor

While the Wysiwyg editor built-in to Magento is great, especially not having to install a wysiwyg module for every Magento installation, it lacks in any way to configure it. I am kind of shocked by this, but, that’s just the way it is right now (at least as of 1.4.2.0 currently).

If you want to be able to upload other types of files besides the few limited image types and media types, I’ll walk you through the ‘right’ way to do it, without modifying core code. We are going to make a very simple module with just 2 files. Here’s how you do it:

Configuration File

Create this file: app/code/local/Prattski/WysiwygFiles/etc/config.xml with the following code:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
    <Prattski_WysiwygFiles>
      <version>1.0.0</version>
    </Prattski_WysiwygFiles>
  </modules>
  <adminhtml>
    <cms>
      <browser>
        <extensions>
          <allowed>
            <jpg>1</jpg>
            <jpeg>1</jpeg>
            <png>1</png>
            <gif>1</gif>
            <pdf>1</pdf>
          </allowed>
        </extensions>
      </browser>
    </cms>
  </adminhtml>
</config>

This configuration file will just build off of Magento’s configuration file, adding allowed extensions (the original configuration file is app/code/core/Mage/Cms/etc/config.xml). As you can see, I added pdf as an allowed extension. Just follow the same format for other extensions if you’d like to add more.

Module File

Create the following file: app/etc/modules/Prattski_WysiwygFiles.xml with the following code:

<?xml version="1.0"?>
<config>
  <modules>
    <Prattski_WysiwygFiles>
      <active>true</active>
      <codePool>local</codePool>
    </Prattski_WysiwygFiles>
  </modules>
</config>

This is what enables the module and allows Magento to recognize it’s there and active.

Once that is done, you should see the module listed in System >> Configuration >> Advanced, and it should work immediately. Enjoy!

weinxin
我的微信
这是我的微信扫一扫