Magento – upload image to skin path from admin system config

configurationmagento-1.9system.xmlupload

In system.xml file you can upload images to /media/… by using:

<upload_dir config="system/filesystem/media" scope_info="1">modulename/folder</upload_dir>
<base_url type="media" scope_info="1">modulename/folder</base_url>

However i need to upload the image in skin/frontend/modulename/themename/css/images directory. I've tried with config="system/filesystem/skin" and type="skin" but it doesn't work.

Best Answer

Before I explain how you can achieve this I want to say that I don't approve of the upload of resources in folders other than media. Your Magento instance should only write files to media and var.

But if you insist.....

You can't do much only my changing the upload_dir and base_url tags.
The config input has the <backend_model> a class that extends Mage_Adminhtml_Model_System_Config_Backend_File.
And in that class there is this method that determines the base folder where the file will be uploaded.

protected function _getUploadRoot($token)
{
    return Mage::getBaseDir('media');
}

This means that everything is uploaded somewhere inside the media folder.
So you need to create a backend model that extends the original one and change the method I mentioned above

Related Topic