Menu Close
    Start a Project Request quote Reading list Switch to dark mode
    magento-hyperlocal-marketplace-guide

    Magento2 File Download Script

    Sometimes you need to create your own file download script in magento, and often people use their own ways to create the script and face problems in executing it, but magento2 has its own script for file download, we can easily use this script for file downloads:

     


    In the above code, this class Magento\Framework\App\Response\Http\FileFactory is used for file download, you can open this and check the parameters that can be passed to the create function, you can also pass content type in the create method, by default it is application/octet-stream.

    Hope this will help you.

    Thanks 🙂 .

    . . .

    Comments (4)

    Add Your Comment

  • Emanuele
    This code works but while download, the file is also written on filesystem. If you want to delete the file after download, modify the return as:

    return $this->_downloader->create(
    $fileName,
    [
    ‘type’ => ‘string’,
    ‘value’ => @file_get_contents($file),
    ‘rm’ => true
    ]
    );

  • Gomathi c
    I have tried this but it’s not working
  • senthil
    Wonderful it’s working as like i expected
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close