Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > Classic ASP

Closed Thread
 
LinkBack Thread Tools
Old August 21st, 2003, 10:34 AM   #1
vor
New Member
 

Join Date: Aug 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 vor is on a distinguished road
Send Binary Data

Just finished writing this little function to send binary files that live in non web accessable folders for a client. Enjoy

Code:
'Function Written by Pedro S.
function SendBinaryFile(fPath)
	dim fName, stream, binData, fso, fileLen

	'If not physical path, then make it *********************
	if instr(fPath,":") = 0 then fPath = Server.MapPath(fPath)
	fName = Right(fpath,len(fpath) - inStrRev(fPath,"\"))
	
	'Check if File Exists and Get its File Size -----------
	Set fso = Server.CreateObject("Scripting.FileSystemObject")  
	if not fso.FileExists(fPath) then  
		Response.Write "File Not Found: " & fName
		Response.End
	end if
	fileLen = fso.GetFile(fPath).size
	set fso = nothing 'end --------------------------------
	
	'Get all the Binary Data ------------------------------
	on error resume next
		set stream = Server.CreateObject("ADODB.Stream")
			stream.Open()
			stream.Type = 1 'Binary
			stream.LoadFromFile(fPath)
			binData = stream.read
		stream.Close()
		set stream = nothing 
		
		'Error Handle Opening and Reading the File.
		if not err = 0 then
			Response.write "Error opening/reading file."
			Response.End
		end if
	on error goto 0 'end ----------------------------------
	
	'Prepare to Send File *********************************
	Response.Buffer = True
	Response.Clear
	Response.AddHeader "content-disposition", "attachment; filename=" & fName
	Response.AddHeader "Content-Length", fileLen
	Response.CharSet = "UTF-8"
	Response.ContentType = "application/octet-stream"
	
	'Send File *******************************************
	Response.BinaryWrite(binData)
	Response.Flush
	
	binData = nothing
end function
vor is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Old August 21st, 2003, 10:38 AM   #2
Rob
Elite Veteran
SuperMember
 
Rob's Avatar
 

Join Date: Jul 2003
Location: Southern UK
Age: 35
Posts: 3,126
Blog Entries: 7
Thanks: 28
Thanked 22 Times in 19 Posts
Rep Altering Power: 0 Rob is a jewel in the rough Rob is a jewel in the rough Rob is a jewel in the rough
Useful Function...

I had a similar one in my toolbox a while ago to do this from a database blob.

Gonna try and dig it out :wink:
__________________
Rob - Webforumz Founder
Web Designer Support Network || Personal Project: Sanctuary for Student Midwives
Rob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Bookmarks

Tags
send , binary , data


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

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
send data from php page to jsp page ktsirig PHP 2 May 2nd, 2008 09:00 AM
binary data(image) loading and display in asp aparna2402 Classic ASP 1 May 17th, 2006 08:26 AM
[SOLVED] Presenting binary values Anonymous User Classic ASP 3 December 7th, 2004 01:50 PM
posting binary data to thirdparty site Webforumz Staff Classic ASP 4 August 10th, 2004 10:57 AM


Search Engine Optimization by vBSEO 3.2.0 RC8