Download Miva EmpresaDownload Miva Mia
Miva Script used functions:
More informations on miva_output_header function  miva_output_header
More informations on file_read function  file_read
More informations on fsize function  fsize
More informations on ssize function  ssize
Tags

miva output header, file read, download , header, content-type, Content-Transfer-Encoding, Content-Length, Content-Disposition, Cache-Control, Pragma

Other Miva Scripts

More informations on Get Image Size function   Install Miva Empresa Mysql5 on Ubuntu
More informations on Get Image Size function  Get image size with Miva Script
More informations on miva_output_header  File Tree with JQuery and Miva Script
More informations on miva_output_header   Miva_output_header and forced download
More informations on miva_output_header   Miva_output_header and excel files

Download Miva Merchant
Search
OK
OK

Force download script with Miva Script

Written by Claudiu Bischoff, on 3 april 2009

In this article I share a small script that can be handy when we want to share files, but we don't want people to see where the actual file is located. The simpliest way is to use the handy miva script function, " miva_output_header "


OVERVIEW

Sharing files is cool, but what if you want to force the download (you don't want just to put a link on the page, but to have the file downloaded directly by the user). This is also interesting for those who want to share files directly from DATA location without moving or copying the file.


This small script override the header of the page and change the content-type to "application/force-download".


Tip Tip: Don't forget to add '<miva standardoutputlevel="compresswhitespace">' on top of your file, as Miva Script can add unwanted characters to your content and the downloaded file will be corrupted.

 

COMPATIBILITY

You must use Miva Empresa 4+ (the miva_output_header and file_read functions aren't available in lower versions of Empresa)

 

THE CODE

You can see the code here: http://mivascript.org/share/scripts/force_download.mv.txt


How to call the function :

<MvCOMMENT> Variables:
l.filename - The name of the file (it is shown when the download pops up)
l.file - the web path of your file (ex: '/download/myfile.ext)
l.location - Can be SCRIPT or DATA

</MvCOMMENT>

 

<mvassign name="l.filename" value="{'somefile.mp3'}">
<mvassign name="l.file" value="{'/folder/somefile.mp3'}">
<mvassign name="l.location" value="{'DATA'}">
<mvassign name="l.content" value="{Generate_Header(l.filename, l.file, l.location)}">
<MvIF EXPR="{ l.content:error }">
    <MvEVAL EXPR="{l.content:error}"><MvEXIT>
<MvElse>
    <MvEVAL EXPR="{l.content}">
</MvIF>


DEMO

   Direct download of an image (you will be prompted to download the image):
      click here

 

TODO

Nothing for the moment :-)

 

COMMENTS

I started a thread in the Miva Merchant (Miva Script section), so don't hesitate: http://extranet.mivamerchant.com/forums/showthread.php?t=20577

 

Miva Merchant, Miva Script, and the Miva Merchant blades logo are registered trademarks of Miva Merchant Corporation. MivaScript.org is not affiliated with Miva Merchant. Copyright © 2009 MivaScript.org - All rights reserved.
Miva Script ressources