Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Some basic questions

  1. #1
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Some basic questions

    Hello, Im new here and just started using html with dreamweaver and I got some simple questions.

    1) I want people to be able to download a file from my site without clicking save as, but when i put the file up it will just open up in the internet browser.

    2) I got some links to usefull tools on my site but I want the links to open in a new window.

    Like i said I just started to use html and im a total newbie

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Question 1: Not really sure , but what I do is, cancel the link and pop-up an alert saying to right-click and hit save as.
    Example:
    Code:
    <a href="#" onclick="alert('Right-click and hit \'save-as\'');return false">
    Question 2: Set your link target to "_blank"
    Example:
    Code:
    <a href="#" target="_blank">
    Simply opens into a new page.

    There is a JavaScript way to do this, but some browsers might have JS disabled, so use targets. It ensures your users get where they want.
    - Mike

  3. #3
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Question no. 1 answer 2.: Actually you cannot force users to download something with plain html. You must use PHP for that except for files like pdf, zip, etc.. etc..

    Question no.2 answer 2: Already been answered by mburt.

  4. #4
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the replys.
    shachi Its not a html file I want people to download. Lets say its a zip how would people be able to download it with just one click.
    Is there any onClick command?

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Dennis_Gull
    2) I got some links to usefull tools on my site but I want the links to open in a new window.
    What about your users? Any browser that allows the author to open new windows (or tabs) should give the user that option, too. If the user has finished at your site, they won't want a new window. If they haven't, they either have the option of opening a new window if they want, or using the Back button, bookmarks (if they liked your site that much to add one), or the history list to return later.

    Mike

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Dennis_Gull
    Lets say its a zip how would people be able to download it with just one click.
    Please use the search facility; you aren't the first person to ask this question.

    Is there any onClick command?
    No, it's more complicated than that (which is why I'd rather not repeat the explanation).

    Mike

  7. #7
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Theoretically speaking, you could use Active X to save a file to your users computer, but that isn't the best idea in the world either. There really isn't a definitive answer for download a file to someones computer.
    - Mike

  8. #8
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mwinter
    Please use the search facility; you aren't the first person to ask this question.
    Didnt find anything that would make a save target as link to work with just html, i did however find some usefull info on how to do it with php.. Can you convert your html to a php or would everything get ****ed up then?

    This is what i found
    Create a file called dowload.php containing the following:

    <?php
    $filename = $_GET['filename'];
    if( ! is_file($filename) || $filename[0] == '.' || $filename[0] == '/' )
    die("Bad access attempt.\n");
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Disposition: attachment; filename=".basename($filename).";");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($filename));
    readfile("$filename");
    exit();
    ?>

    When you want to call the file use:
    http://www.yourwebsite.com/download....atfilename.pdf

    That'll bring up the box asking to open, save, etc.
    Maybe theres something similar to html texts?
    Last edited by Dennis_Gull; 08-19-2006 at 05:28 PM.

  9. #9
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Dennis_Gull
    Didnt find anything that would make a save target as link to work with just html,
    That's because there isn't any way to do so with HTML.

    Can you convert your html to a php or would everything get ****ed up then?
    If your server is configured to process PHP, there should be no problem.

    This is what i found
    Here, on Dynamic Drive? I hope not.

    $filename = $_GET['filename'];
    The script should check that a "filename" parameter was included in the query string, first.

    if( ! is_file($filename) || $filename[0] == '.' || $filename[0] == '/' )
    It should reject any filenames that contain a path separator entirely, This code is also vulnerable to attack through the file scheme.

    die("Bad access attempt.\n");
    That's not exactly a helpful way to terminate a script.

    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    None of those headers are necessary.

    header("Content-Type: application/octet-stream");
    That one's fine.

    header("Content-Type: application/download");
    That's also unnecessary.

    header("Content-Disposition: attachment; filename=".basename($filename).";");
    The basename function shouldn't be necessary if path separators are rejected.

    header("Content-Transfer-Encoding: binary");
    That's a MIME header and has no business being used in a HTTP response.

    That'll bring up the box asking to open, save, etc.
    That's optimistic; it may bring up a dialogue box.

    For some previous discussions in this forum, see the threads link to download pdf and force to download a file (beware: bad code).

    Mike

  10. #10
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hehe I didnt find it here, will check the links you gave me.. btw would it work to just replace the .html with .php and update all the links?

    Thanks for all the replys

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •