1

I am wondering if anyone can provide an insight into how the config to store media files in the database works. A question I have is - there are many different types of media files. CMS, product images, and 3rd party extensions - are all these different types of media files supported with this option? Any potential issues to look out for?

3

Magento has explained this in their doc: http://docs.magento.com/m1/ce/user_guide/system-operations/media-storage-database.html

The only thing I have noticed is that, magento will need to run a php script whenever the user access a media file if it can't find the file in the file system. The script will save that to the file system once it is fetched from the database. The real problem will start if your webserver rewrites are disabled in magento, in that case the php file will need to run for each request, which will definitely slow down your site.

Adding some important points from that url below:

How to configure?

By default, all images, compiled CSS files, and compiled JavaScript files of the Magento instance are stored in the file system on the web server. You can choose to store these files in a database on a database server. One advantage of this approach is the option of automatic synchronization and reverse synchronization between the web server file system and the database. You can use the default database to store media or create a new one. To be able to use a newly created database as media storage, you must add information about it and its access credentials to the local.xml file.

If you want to use a different db for media, in your local.xml you can add an additional config node as below and select that in the configuration (System >> Configuration >> System >> Storage Configuration for Media (Make sure the config scope is default)):

<default_setup_media>
    <connection>
        <host><![CDATA[localhost]]></host>
        <username><![CDATA[root]]></username>
        <password><![CDATA[]]></password>
        <dbname><![CDATA[magento]]></dbname>
        <initStatements><![CDATA[SET NAMES utf8]]></initStatements>
        <model><![CDATA[mysql4]]></model>
        <type><![CDATA[pdo_mysql]]></type>
        <pdoType><![CDATA[]]></pdoType>
        <active>1</active>
    </connection>
</default_setup_media>

How it works?

When the customer opens the store page, its browser requests the HTML code and the media specified in the HTML code from the Magento system. The system searches the requested media in the file system and passes it to the browser, if it is found. If the system does not find the media in the file system, it requests the media from the database specified in the settings, places the media to the file system, and sends it to the customer’s web browser.

To get the files from the database to the file system on the web server a PHP script is used (I think it is get.php). When the browser requests media from the web server, there are two alternatives for when a PHP script is run:

  • If web server rewrites are enabled in the Magento system and supported by the server, the PHP script is run only when the requested media is not found in the web server file system.
  • If web server rewrites are disabled in the Magento system or not supported by the server, the PHP script is run in any case, even when the required media exists in the file system of the web server.

How to Synchronize?

There is button "Synchronize" in System >> Configuration >> System >> Storage Configuration for Media, click that button once you configured everything.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.