I'm still learning magento and I have a custom module which will accept certain inputs and save those in an excel sheet. I wonder how I can tell my module to where the excel file should be saved.

I have googled a lot and found nothing except the programmatical way of saving an image.

A little help is greatly appreciated.

1 Answer 1


I assume you are uploading your file from a controller.
If that's true, you can add this to the controller

protected function _uploadAndGetName($input, $destinationFolder, $data)
    try {
        if (isset($data[$input]['delete'])) {
            return '';
        } else {
            $uploader = new Varien_File_Uploader($input);
            $result = $uploader->save($destinationFolder);
            return $result['file'];
    } catch (Exception $e) {
        if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
            throw $e;
        } else {
            if (isset($data[$input]['value'])) {
                return $data[$input]['value'];
    return '';

Then you can use this method to upload the file where ever you want and get the name after upload like this:

$input = 'file'; //this is the name of the form file input
$destination = 'path/to/destination'; //where you want the file uploaded
$data = $this->getRequest()->getPost();
$file = $this->_uploadAndGetName($input, $destination, $data);
  • thanks a lot... this is exactly what I was looking for.. :)
    – DB-Admin
    Commented Aug 5, 2015 at 7:07

Your Answer

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

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