Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Linking to file with different filename...

Options
  • 19-01-2012 2:23pm
    #1
    Registered Users Posts: 1,657 ✭✭✭


    Sorry about the dodgy subject... But anyway.. Is there any way (the simpler the better) of accomplishing the following.

    I have a file that I want a user on a website to be able to download. Let's call it example.pdf

    However, it's stored on the server as example.pdf.28u028402840

    Is there any (preferably simple even pure HTML if possible) way of linking to this file, but it appears to the user to be example.pdf (ESPECIALLY that it saves as example.pdf and can be opened in the browser if it has a pdf reader extension)

    I'm using PHP on an apache server. I don't want to use .htaccess as the filename could be changing all the time depending on what the admin is doing. Next week it could be another_example.pdf.2094028402


Comments

  • Registered Users Posts: 339 ✭✭duffman85


    From PHP manual on headers - example 1 http://php.net/manual/en/function.header.php
    [PHP]<?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');

    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');

    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>
    [/PHP]

    Would something like this work?
    Then make the link as[PHP]<a href="download.php?id=28u028402840">Download</a>[/PHP]
    then in download.php do checks on the id and check that the file exists.
    You'd have to know the id in advance.


  • Registered Users Posts: 16,413 ✭✭✭✭Trojan




  • Registered Users Posts: 1,477 ✭✭✭azzeretti


    Trojan wrote: »
    ln -s
    Symbolic link well be tricky if you've no console access, say in a hosted solution.

    Is it just one file? And always will be?
    or is it multiple files?


  • Registered Users Posts: 851 ✭✭✭TonyStark


    komodosp wrote: »
    Sorry about the dodgy subject... But anyway.. Is there any way (the simpler the better) of accomplishing the following.

    I have a file that I want a user on a website to be able to download. Let's call it example.pdf

    However, it's stored on the server as example.pdf.28u028402840

    Is there any (preferably simple even pure HTML if possible) way of linking to this file, but it appears to the user to be example.pdf (ESPECIALLY that it saves as example.pdf and can be opened in the browser if it has a pdf reader extension)

    I'm using PHP on an apache server. I don't want to use .htaccess as the filename could be changing all the time depending on what the admin is doing. Next week it could be another_example.pdf.2094028402


    In pure HTML... no.

    You need a small script to find the file read it into memory and then output it as the new file with the modified name.

    If you want the latest you look at the time stamp on the file and the process this one. If you want one with a particular name then you would use a regular expression to parse the file name.

    It adds overhead to your web server, but if it's not going to be downloaded a million times a minute.


  • Registered Users Posts: 1,657 ✭✭✭komodosp


    Well it'll be different files all the time, and two files at any one time, as the admin will be uploading and replacing on a weekly basis, but there is no problem matching up the "real" file name to the perceived one as they are stored in the db.
    Anyway yeah I was afraid of that... I didn't want to go writing extra PHP and I wanted the user to think that the link was to that file, but ah well...


  • Advertisement
  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    PHP would be the way I'd go, but would a .htaccess redirect do the trick ?


  • Registered Users Posts: 1,657 ✭✭✭komodosp


    No, the files will be changed on a regular basis through the CMS, so the file name would change all the time too.


  • Registered Users Posts: 1,657 ✭✭✭komodosp


    Thanks folks

    Decided to go with the PHP (duffman's) solution


Advertisement