Creating Folders Safely from Magento Code
Modules that save uploads or generated files need somewhere to put them, and that folder may not exist yet on a fresh install. Magento 1 has a helper that creates the whole path in one go, but only if it is missing.
Example
This builds a per-record folder under media/registration:
$baseDir = Mage::getConfig()->getBaseDir('media').DS.'registration'.DS.$this->getId();
Mage::getConfig()->createDirIfNotExists($baseDir);
Keep user uploads outside executable paths, and block PHP execution in the media folder at web server level.
Heads up: this guide applies to Magento 1, which stopped receiving official security updates in June 2020. If your store still runs it, plan a move to Magento 2 or Adobe Commerce soon. We can help with the migration.
Need a second pair of eyes on this? Our team handles Magento development every week. See how we can help.