1

I am trying to upload a file from frontend. as bellow,

.phtml file

<label for="sb_link">Image</label>
<input type="file" id="bs_image" name="bs_image" required="true"/>

and in my controller I am doing

      if (isset($_FILES['bs_image']['name']) && $_FILES['bs_image']['name'] != '') {
                $path = Mage::getBaseDir() . '/test';
                if (!file_exists($path)) {
                    mkdir($path, 777, true);
                } try {

                    $fname = $_FILES['bs_image']['name'];
//                 $fname = $this->getRequest()->getParam('bs_image');
                    $uploader = new Varien_File_Uploader('bs_image');
                    $uploader->setAllowedExtensions(array('png', 'gif', 'jpeg', 'docx'));
                    $uploader->setAllowCreateFolders(true);
                    $uploader->setAllowRenameFiles(false);
                    $uploader->setFilesDispersion(false);
                    $uploader->save($path, $fname);
                } catch (Exception $e) {
                    echo 'Error Message: ' . $e->getMessage();
                }
            }

folder is present, and getting no error/exception, but file is not in folder. or there is an other way to do it. I was following Owais Kiani's post

9
  • @Qaisar Satti , what do you say about it May 10, 2016 at 9:55
  • did you add enctype="multipart/form-data" May 10, 2016 at 10:43
  • Yes, <form id="product-form" action="<?php echo Mage::getUrl('abc_checkout/cart/addall'); ?>" method="post" enctype="multipart/form-data"> May 10, 2016 at 10:50
  • print_r($_FILES); what is output of this? May 10, 2016 at 10:52
  • 1
    path problem update the path code then check and also clear ur cache. and check the folder permission is 777 May 10, 2016 at 11:00

1 Answer 1

1

replace $path = Mage::getBaseDir() . '/test'; with $path = Mage::getBaseDir('media') . DS . 'test/';

Also clear ur cache. and check the folder permission is 777

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.