2

I have created custom module in magento with image upload attribute. Image name was successfully stored in DB table. But image doesn't upload to the target folder.

I have tried with this following code. please show me "what am i doing wrong here"

 $uploader = new Varien_File_Uploader('fileinputname');
 $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
 $uploader->setAllowRenameFiles(false);
 $uploader->setFilesDispersion(false);
 $path = Mage::getBaseDir('media') .DS. 'foo'.DS ;
 $uploader->save($path, $_FILES['fileinputname']['name']);
asked Oct 11, 2013 at 9:49
4
  • Check if target folder has write permissions Commented Oct 11, 2013 at 10:19
  • i think you verified magentocommerce.com/wiki/5_-_modules_and_development/admin/…, for this, first check print_r($_FILES);exit; before the if condition if(isset($_FILES['fileinputname']['name']) and (file_exists($_FILES['fileinputname']['tmp_name']))) {, you'll find the key you used is wrong. Commented Oct 11, 2013 at 10:21
  • i have edit $path as $path = Mage::getBaseDir('media').'/foo/'; Now its working Fine. THank you dudes Commented Oct 16, 2013 at 12:48
  • I have added my answer @Marius Commented Mar 20, 2014 at 5:33

2 Answers 2

1

I just edit file path like

 $path = Mage::getBaseDir('media').'/foo/';

instead of

$path = Mage::getBaseDir('media') .DS. 'foo'.DS ;

That's All. Now Its working well

For further details please lookout this post

answered Mar 20, 2014 at 5:19
1

Try Below code,Below code works for me and just I give permission to directory where image will be stored

$uploader = new Varien_File_Uploader('fileinputname');
 $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
 $uploader->setAllowRenameFiles(false);
 $uploader->setFilesDispersion(false);
 $path = Mage::getBaseDir('media') .DS. 'foo'.DS ;
 if(!is_dir($path))
 mkdir($path, 0777, true);
 $uploader->save($path, $_FILES['fileinputname']['name']);
answered Sep 22, 2015 at 7:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.