Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Web Design (WordPress, Joomla, etc.) download this file” button

  • Curtis Thompson

    May 4, 2005 at 9:08 pm

    hello…

    the low-budget way is to just make the file itself the link…otherwise, you can get fancy and make a scripted page that streams binary content with the file’s mime type, but the former usually works well enough for people…

    but the latter does offer the ability to stream as a raw octet stream, which means that the user’s browser won’t recognize it and try to open it for you inline, which might be what you’re trying to get around (the user gets a file download dialog and they can save it wherever they want or just open it)…

    sitruc

  • Mark Cookman

    May 5, 2005 at 2:16 pm

    Thanks for the advice, I have been doing the low (no) budget way for a while but I need to come into the new millenium now!

    I am using .pl script to generate .htacces for my folder and can generate a page, I want to learn how to embed files so that they will download rather than try to open.
    Is pearl the right way ? any suggestions?

  • Curtis Thompson

    May 5, 2005 at 3:44 pm

    hello…

    perl can certainly do this, or pretty much any scripting language. the end result will be the same as if you were to link to a file that your browser doesn’t recognize – you’ll get a (on ie/windows anyway, other browsers with download managers will likey just grab it anyway) open/save/cancel dialog and then the decision can be made as to what to do with the file.

    but if your browser recognizes the file, it will display it inline (so like if you linked ot a jpg, then your browser knows all about those) and won’t offer a file dialog, but rather it will just display it on its own. the way to get around this is to stream the content as an “application/octet-stream” or (“application/x-download” – either one will work) mime type, which the browser will then just hand on to the user’s system and it will deal with the file…

    php is really equipped to do this – here’s a sample from their docs:

    // open the file in a binary mode
    $name = “.publicdevimgok.png”;
    $fp = fopen($name, ‘rb’);
    
    // send the right headers
    header(“Content-Type: image/png”);
    header(“Content-Length: ” . filesize($name));
    
    // dump the picture and stop the script
    fpassthru($fp);
    exit;
    

    so you could just switch the Content-Type header to “application/octet-stream” instead of “image/png” and you’d be good to go. you can also get much fancier and only allow the users to download certain file types (good idea regardless), and then create a hash (array) of mime types to extensions…

    perl can do it the same thing – here’s a tutorial on that…php sorta grew out of perl and unix, so a lot of the php above will look very familar to this perl code:

    https://www.sitepoint.com/print/file-download-script-perl

    hope that helps! lemme know if you have any questions…both these ways are nice because before streaming the file, you can do any code you want to verify the user (check session in php, ip in either, etc.)…

    sitruc

  • Mark Cookman

    May 5, 2005 at 6:06 pm

    ooooh thats nice and meaty – thanks v much! I will spend time on it 🙂

  • Mark Cookman

    May 6, 2005 at 1:58 pm

    Reading the cow I found your php_client_area script – wow thanks, its got to be a better solution.

    Done the config and saw a list of files at my system url root , is that wrong already?
    – click on login.php gives me a screen with the correct $SYSTEM_NAME I put into config file -so i’m hopefull its nearly there:

    When I login as sample or admin I get a “too many redirects” error from safari browser.
    When I login with capitals – Sample or Admin it gives me repeated goes at entering password.

    May I trouble you for a hint 🙂

  • Mark Cookman

    May 9, 2005 at 5:51 pm

    Hello ….that started me off on a weekend learning fest that has put bags under my eyes! Spinoff : I can run pearl cgi on my home mac now!

    I have gone through the client_area install thoroughly as I can but it says “too many redirects” as I login.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy