FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

File Download

 


Shike
How can I set a file to automatically download instead of opening in the browser. I have files that are for a specific program, and as such have unique file extensions. Any help would be greatly appreciated.
mathiaus
Not sure about your file extensions but having it open in the same window can be done very simply Smile
Code:
<a href="FILE_URL" target="_self">FILE_NAME</a>


Why not put everything in a zip and/or tar.gz? Less disk space and quicker download for users using less bandwidth.
Nyizsa
The simplest method is telling your clients to download the file. For example:
whatever.yzr - Right click on this link, then choose Save As...
Shike
Nyizsa, Thats what I was thinking, but I was wondering if there was a way to have it done automatically.


Thanks for the input. Smile
eepman
You can easily do this in php.
Code:
If you can use PHP, you can do this through the header() function - you
would pass $file to a page containing the code below - e.g.
<a href="download.php?file=foobar.mp3">download foobar</a>

the PHP code in download.php :

<?php

urlencode($file) ."\";',1000);";

$f = @fopen($file,"r");
if (!$f)
    print "<HTML><BODY>Failed to download $file</BODY></HTML>";
else
    {
    header("Content-Type: application/octet-stream");
    header("Content-Length: ".filesize($file));
    header("Content-Disposition: attachment; filename=" .basename($file));
    $data="";
    while (!feof($f)) $data.=fread($f,64000);
    fclose($f);
    print $data;
    }
?>


This code from http://lists.evolt.org/archive/Week-of-Mon-20020513/112746.html
[theLIst]
Shike
eepman, this is exactally what I was looking for. thanks.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.