View Full Version : Some basic questions
Dennis_Gull
08-19-2006, 03:28 PM
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 :)
mburt
08-19-2006, 03:56 PM
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:
<a href="#" onclick="alert('Right-click and hit \'save-as\'');return false">
Question 2: Set your link target to "_blank"
Example:
<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.
shachi
08-19-2006, 04:07 PM
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.
Dennis_Gull
08-19-2006, 04:27 PM
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?
mwinter
08-19-2006, 04:29 PM
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
mwinter
08-19-2006, 04:38 PM
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
mburt
08-19-2006, 04:42 PM
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.
Dennis_Gull
08-19-2006, 05:22 PM
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.php?filename=acrobatfilename.pdf
That'll bring up the box asking to open, save, etc.
Maybe theres something similar to html texts?
mwinter
08-19-2006, 07:34 PM
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 (http://www.dynamicdrive.com/forums/showthread.php?t=3407) and force to download a file (http://www.dynamicdrive.com/forums/showthread.php?t=6139&highlight=force+download) (beware: bad code).
Mike
Dennis_Gull
08-19-2006, 08:55 PM
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
mburt
08-19-2006, 09:43 PM
No, but it would work if you compressed it and put it in a .zip folder. The download will automatically prompted.
Dennis_Gull
08-20-2006, 01:15 AM
No, but it would work if you compressed it and put it in a .zip folder. The download will automatically prompted.
I did change the html to php and uploaded it to my tracker and it works great..
Now I only have to add that download script to my ftp and im done :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.