Logo
X
  • Who We Serve
    • By Role

      • CEO / Business Executives
      • CTO / IT Professionals
      • COO / Operations Head
    • By Industries

      • Healthcare
      • Digital Commerce
      • Travel and Transportation
      • Real Estate
      • Software and Technology
  • Our Technology Focus
    • Web
    • Mobile
    • Enterprise
    • Artificial Intelligence
    • Blockchain
    • DevOps
    • Internet Of Things
  • Discover Daffodil
    • About
    • Leadership
    • Corporate Social
      Responsibility
    • Partners
    • Careers
  • Resources
    • Blog

    • E-Books

    • Case Studies

    • View all resources

  • Who We Serve
    • By Role

      • CEO / Business Executives
      • CTO / IT Professionals
      • COO / Operations Head
    • By Industries

      • Healthcare
      • Digital Commerce
      • Travel and Transportation
      • Real Estate
      • Software and Technology
  • Our Technology Focus
    • Web

      Create responsive web apps that excel across all platforms

    • Mobile

      User centric mobile app development services that help you scale.

    • Enterprise

      Innovation-driven enterprise services to help you achieve more efficiency and cost savings

      • Domains
      • Artificial Intelligence
      • DevOps
      • Blockchain
      • Internet Of Things
  • Discover Daffodil
    • About
    • Leadership
    • Corporate Social Responsibilities
    • Partners
    • Careers
  • Resources
    • Blog

      Insights for building and maintaining your software projects

    • E-Books

      Our publications for the connected software ecosystem

    • Case Studies

      The impact that we have created for our clients

    • View all resources
daffodil-logo
Get in Touch
  • What We Do
    • Product Engineering

    • Discover & Frame Workshop
    • Software Development
    • Software Testing
    • Managed Cloud Services
    • Support & Maintenance
    • Smart Teams

    • Dedicated Teams
    • Offshore Development Centre
    • Enterprise Services

    • Technology Consulting
    • Robotic Process Automation
    • Legacy Modernization
    • Enterprise Mobility
    • ECM Solutions
  • Who We Serve
    • By Industry

    • Healthcare
    • Software & Technology
    • Finance
    • Banking
    • Real Estate
    • Travel & Transportation
    • Public Sector
    • Media & Entertainment
    • By Role

    • CEO / Business executives
    • CTO / IT professionals
    • COO / Operations
  • Our Expertise
    • Mobility
    • UI/UX Design
    • Blockchain
    • DevOps
    • Artificial Intelligence
    • Data Enrichment
    • Digital Transformation
    • Internet of Things
    • Digital Commerce
    • OTT Platforms
    • eLearning Solutions
    • Salesforce
    • Business Intelligence
    • Managed IT Services
    • AWS Services
    • Application Security
    • Digital Marketing
  • Case Studies
  • Discover Daffodil
    • About us
    • Partnership
    • Career & Culture
    • Case Studies
    • Leadership
    • Resources
    • Insights Blog
    • Corporate Social Responsibility
Get in Touch
resources-bg.jpg

Software Engineering Insights

Creating Download Link to Direct File in Magento

Jun 11, 2015 11:08:45 PM

  • Tweet

One of the most beautiful parts of Magento lies in its usage. From the admin control you can basically oversee and spearhead any feature you wish to utilize. Though proper implementation and feasibility may seem difficult or impossible at times but even these intricate features can be utilized very adeptly.

magento1

One such feature that I implemented was for a client who wanted to provide a direct download link of a file stored in a “var” folder.

Basically I have a custom admin module and client want to provide a link in grid that will directly download the file. File may be an image or a pdf. File location is within var folder and as it is known we cannot access var folder directly so we need to create admin controller to achieve this functionality.

First we need to call render function in grid.php file.

Path of file is – app/code/local/ModuleNamespace/ModuleName/Block/Adminhtml/ModuleName/Grid.php

 [php]$this->addColumn("column_name", array(

"header" => Mage::helper("registration")->__("Column Name"),
"index" => "column_name",
'sortable' => true,
'type' => 'text',
'renderer' => 'ModuleNamespace_ModuleName_Block_Adminhtml_Template_Grid_Renderer_File' )); [/php]

This will call render function of file.php and pass path of the file that we need to download.

Path of file should be –  app/code/local/ModuleNamespace/ModuleName/Block/Adminhtml/Template/Grid/Renderer/File.php

New Call-to-action

Now file.php should be like this-

[php]<?php class ModuleNamespace_ModuleName_Block_Adminhtml_Template_Grid_Renderer_File extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {

public function render(Varien_Object $row) {
return $this->_getValue($row);
}

protected function _getValue(Varien_Object $row) {

$val = $row->getData($this->getColumn()->getIndex());
$parts = explode("/", $val);
$filename = end($parts);
$url = Mage::helper("adminhtml")->getUrl("moduleName/adminhtml_moduleName/downloadfile", array('filename' => $filename)); $out = "<a href='".$url."'>". $val ."</a>";
return $out;
}
}[/php]

here $val contain the path of file which should be like

“var/www/projectName/var/folderName/file.jpg”

$filename will get the file name like “file.jpg”. If you already have the file name then there is no need to explode it. Now I am cal

Topics: Digital Commerce Open Source

Ankita Agrawal

Written by Ankita Agrawal

Ankita Agrawal is leading Magento team and providing best in class e-commerce products and aimed at client satisfaction. She is very good at innovating and implementing latest marketplace solutions. Having a great experience of providing customized and featured products, she fits best for handling higher complexity projects.

Previous Post

previous_post_featured_image

Magento Checkout Problem - Custom Customer Attribute not Saved in Checkout Register

Next Post

next_post_featured_image

Mobile App 'App'rehension? These 6 reasons will make you think twice

Stay Ahead of the Curve with Our Weekly Tech Insights

  • Recent
  • Popular
  • Categories

Lists by Topic

  • Software Development (175)
  • Artificial Intelligence (169)
  • Mobile App Development (166)
  • Healthcare (137)
  • DevOps (80)
  • Digital Commerce (60)
  • Web Development (57)
  • CloudOps (54)
  • Digital Transformation (37)
  • Fintech (36)
  • UI/UX (29)
  • Software Architecture (27)
  • On - Demand Apps (26)
  • Internet of Things (IoT) (25)
  • Open Source (25)
  • Outsourcing (24)
  • Blockchain (21)
  • Newsroom (21)
  • Salesforce (21)
  • Technology (18)
  • Software Testing (16)
  • StartUps (16)
  • Customer Experience (14)
  • Robotic Process Automation (13)
  • Voice User Interface (13)
  • Javascript (11)
  • OTT Apps (11)
  • Business Intelligence (10)
  • Data Enrichment (10)
  • Infographic (10)
  • Big Data (9)
  • Education (9)
  • Microsoft (6)
  • Real Estate (5)
  • Banking (4)
  • Game Development (4)
  • Enterprise Mobility (3)
  • Hospitality (3)
  • eLearning (2)
  • Public Sector (1)
see all

Posts by Topic

  • Software Development (175)
  • Artificial Intelligence (169)
  • Mobile App Development (166)
  • Healthcare (137)
  • DevOps (80)
  • Digital Commerce (60)
  • Web Development (57)
  • CloudOps (54)
  • Digital Transformation (37)
  • Fintech (36)
  • UI/UX (29)
  • Software Architecture (27)
  • On - Demand Apps (26)
  • Internet of Things (IoT) (25)
  • Open Source (25)
  • Outsourcing (24)
  • Blockchain (21)
  • Newsroom (21)
  • Salesforce (21)
  • Technology (18)
  • Software Testing (16)
  • StartUps (16)
  • Customer Experience (14)
  • Robotic Process Automation (13)
  • Voice User Interface (13)
  • Javascript (11)
  • OTT Apps (11)
  • Business Intelligence (10)
  • Data Enrichment (10)
  • Infographic (10)
  • Big Data (9)
  • Education (9)
  • Microsoft (6)
  • Real Estate (5)
  • Banking (4)
  • Game Development (4)
  • Enterprise Mobility (3)
  • Hospitality (3)
  • eLearning (2)
  • Public Sector (1)
see all topics

Elevate Your Software Project, Let's Talk Now

Awards & Accolades

dj
dj
dj
dj
dj
Aws-certification-logo
microsoft-partner-2-1
microsoft-partner
google-cloud-partne
e-UI-Path-Partner-logo
partner-salesforce-reg-consulting-partner-1-1
daffodil-logo
info@daffodilsw.com
  • Home
  • About Daffodil
  • Locations
  • Privacy Policy
  • Careers

© 2025 Daffodil Unthinkable Software Corp. All Rights Reserved.

[fa icon="chevron-up"]