Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » Downloading files


Downloading files

Reply
  #1 (permalink)  
Old 07-21-05, 07:28 AM
alane alane is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 71
Thanks: 6
Thanked 0 Times in 0 Posts
Downloading files

Simple question no doubt for many but new to offering files for download on my own site.

I am developing a site with links to download a number of PDF files and listing them on various index pages as a link to the file.

Normally they appear and if you left click they will open Acrobat, download and appear or if you right click you get the option of a 'save as' dialogue box.

What I want to do is exactly as the following site - http://www.c-point.com/download2.htm#javascripteditor - where if you left click you immediatly get the 'open / save as dialogue box immediatly.

How is it done please?? As I said above no doubt simple if you know how!

Thanks Alan
Reply With Quote
  #2 (permalink)  
Old 07-21-05, 10:26 AM
angel.of.wisdom angel.of.wisdom is offline
Newbie Coder
 
Join Date: Jul 2005
Location: lisbon, portugal
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by alane
Simple question no doubt for many but new to offering files for download on my own site.

I am developing a site with links to download a number of PDF files and listing them on various index pages as a link to the file.

Normally they appear and if you left click they will open Acrobat, download and appear or if you right click you get the option of a 'save as' dialogue box.

What I want to do is exactly as the following site - http://www.c-point.com/download2.htm#javascripteditor - where if you left click you immediatly get the 'open / save as dialogue box immediatly.

How is it done please?? As I said above no doubt simple if you know how!

Thanks Alan
i think that PDF files are automatically opened on browsers,but ZIP files aren't,so ZIP files are downloaded. what i recommend is that you should ZIP your PDF's,so that they are downloaded instead of opened.
Keep in mind that,altough a PDF file is opened,you can always save it on the "Save" button in the toolbar.

Hope this answered your question.

angel.of.wisdom
(as i always say, forgive my english)
Reply With Quote
  #3 (permalink)  
Old 07-23-05, 02:40 AM
alane alane is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 71
Thanks: 6
Thanked 0 Times in 0 Posts
angel.of.wisdom

Thanks for reply. I will zip files as suggested. It will also make files slightly smaller for downloading.

(as i always say, forgive my english)?? - Nothing wrong with your english. What country are you in?

I have just checked in your profile. As I said nothing wrong with english.

Thanks again
Alan
Reply With Quote
  #4 (permalink)  
Old 07-23-05, 05:47 AM
minority minority is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
only way to force it would be through a programming language eg asp or php.

asp version

Code:
<%	
 strFile= request("link")
	
  dim ads, fso, f

  Response.Buffer = True
  Response.Clear

  set ads = Server.CreateObject("ADODB.Stream")
  ads.Open
  ads.Type = 1

  on error resume next
  set fso = Server.CreateObject("Scripting.FileSystemObject")

  set f = fso.GetFile(strFile)
  intFilelength = f.size
  ads.LoadFromFile(strFile)

  if err then
    Response.Write "<h1>Error: </h1><font color='#485e9e'>" & err.Description & "</font><p>"
    Response.End
  end if

  Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
  Response.AddHeader "Content-Length", intFilelength
  Response.Charset = "UTF-8"
  Response.ContentType = "application/octet-stream"
  Response.BinaryWrite ads.Read
  Response.Flush

  ads.Close
  set ads = Nothing
  %>
Reply With Quote
  #5 (permalink)  
Old 07-23-05, 01:44 PM
alane alane is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 71
Thanks: 6
Thanked 0 Times in 0 Posts
Thanks for that minority.

Can you give idea how to do this in php as I cannot use asp. Sorry to be a pain.

I'll also try posting question in php forum so thanks for idea.
Reply With Quote
  #6 (permalink)  
Old 07-23-05, 02:03 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by alane
Thanks for that minority.

Can you give idea how to do this in php as I cannot use asp. Sorry to be a pain.

I'll also try posting question in php forum so thanks for idea.
Try:


$zfile = "testfile.zip";


// the file to deliver...
$filename = "/home/mysite/files/$zfile";

// stream image out to browser
header('Content-type: application/x-zip-compressed');
header('Content-transfer-encoding: binary');
header("Content-Disposition: attachment; filename=$zfile");
header('Content-length: '.filesize($filename));
readfile($filename);


That's the simple way to do it. There's a fancier way but I don't have the code handy.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make condition(20 posts in forum, one file per one day) for downloading files? renatik PHP 2 01-06-05 03:53 PM
downloading php files mjaniszewski2 PHP 3 11-01-04 02:02 PM
netadmin project - delete files georgeminton Visual Basic 0 03-03-04 04:03 PM
How to <!--include .htm files in .php files cstallins PHP 4 10-27-03 05:35 AM


All times are GMT -5. The time now is 08:45 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.