I have a module using which I need to upload an image. However Magento does not allow that.This is the stack trace that I have obtained
Unable to create directory 'http://localhost/rajeev/magento/media/rktsizechart/sc'.
#0 /home/rajeev/public_html/magento/lib/Varien/File/Uploader.php(183): Varien_File_Uploader->_createDestinationFolder('http://localhos...')
#1 /home/rajeev/public_html/magento/app/code/local/Rkt/Sizechart/controllers/Adminhtml/Cms/SizechartController.php(130): Varien_File_Uploader->save('http://localhos...', 'guitar.jpg')
#2 /home/rajeev/public_html/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Rkt_Sizechart_Adminhtml_Cms_SizechartController->saveAction()
#3 /home/rajeev/public_html/magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('save')
#4 /home/rajeev/public_html/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#5 /home/rajeev/public_html/magento/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#6 /home/rajeev/public_html/magento/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#7 /home/rajeev/public_html/magento/index.php(87): Mage::run('', 'store')
#8 {main}
Beautiful. Path looks ok. Then why it does not work. So I debugged more. The last error is thrown from Varien_File_Uploader->_createDestinationFolder()
. This is the code that we can see there.
private function _createDestinationFolder($destinationFolder)
{
if (!$destinationFolder) {
return $this;
}
if (substr($destinationFolder, -1) == DIRECTORY_SEPARATOR) {
$destinationFolder = substr($destinationFolder, 0, -1);
}
if (!(@is_dir($destinationFolder) || @mkdir($destinationFolder, 0777, true))) {
throw new Exception("Unable to create directory '{$destinationFolder}'.");
}
return $this;
}
No need to look full code. I am damn sure this is the code that makes problem here
mkdir($destinationFolder, 0777, true);
Now I dont know why it returns false
here. I have tried to put some urls directly over there. I can see that, if I am pointing to outside media
directory, it returns true
.
media
directory has 777
permission. Then how the hell is this happening ?
In general I want to know,
How can I properly debug magento uploading error ?
What are the main reasons that cause magento file uploadation not successful ?
$destinationFolder
? why does it have seem to be a urlVarien_File_Uploader->_createDestinationFolder('http://localhos...')
– Renon Stewart Oct 20 '14 at 15:52http://localhost/rajeev/magento/media/rktsizechart/sc
this is the value of that variable.$path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'rktsizechart' . DS . 'sc' . DS ;
this is the code that I am using to generate path. – Rajeev K Tomy Oct 20 '14 at 15:55getBaseDir
and notgetBaseUrl
– David Manners Oct 20 '14 at 16:01Mage::getBaseUrl
instead ofMage::getBaseDir
. Thanks for tracing it. Please post this as an answer – Rajeev K Tomy Oct 20 '14 at 16:06