Hidden feature: Joomla’s media folder

Traditionally, Joomla extensions stored all their assets (images, javascript, css, flash files…) inside the extension’s folder. However, because these files are supposed to be publicly accessible, and all other files should stay hidden, that doesn’t really make sense. Fortunately, this was fixed in Joomla 1.5.4. Extensions can now use the /media folder.

How does it work?

Very easy: simply add a media tag in your extension’s manifest file.

Before:

<files folder="site">
 <folder>some_folders</folder>
 <folder>css</folder>
 <folder>images</folder>
 <folder>js</folder>
 <file>index.html</file>
 <file>mycomp.php</file>
</files>

After:

<files folder="site">
 <folder>some_folders</folder>
 <file>mycomp.php</file>
</files> 

<media destination="com_mycomp" folder="media">
 <folder>css</folder>
 <folder>images</folder>
 <folder>js</folder>  
 <file>index.html</file>
</media>

Inside your installable package, you should now have the folders /site and /media. During the extension’s installation, the files from /media will be copied to /media/com_mycomp (or plg_myplugin or mod_mymodule).

Benefits

Separating publicly accessible assets from the rest of the system like this has some security advantages. Ideally, you’d move all other files below the document root, increasing security. Joomla doesn’t support this yet. What you can do however, is add a htaccess file in /com_mycomp with ‘deny from all‘. This way you don’t need to litter your component with index.html files and defined(‘_JEXEC’) or die(); statements. Of course, this assumes that the end user’s host has AllowOverride turned on.

Up next

What is Joomlatools Connect and how will it ease my workload?

Joomlatools Connect makes your Joomla site more stable and faster.

Read more →

How our enterprise hosting helped SBHPP get more leads

Read about how we helped SBHPP improve the performance of their website to get more leads

Read more →

How do I allow users to view but not download documents?

DOCman with Google Drive allows users to view but not download documents.

Read more →