Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2004, 09:46 AM
Registered User
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Image does not download

hi,
 i have created a hyperlink to an image, but instead of being downloaded, the image is opened in the same page itself. while if i give the hyperlink of an application(exe file), a download dialog box appears to save the file first. how can i make the same download dialog box appear for the image also.

:samar
 
Old July 10th, 2004, 04:31 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I can think of two ways to do this.

1) Compress the image into a .zip format. Then link to the .zip file; it will download it.

2) Use a server-side language to force a download. If you have access to ASP or PHP, let me know and I'll show you how.

HTH,

Snib

<><
 
Old July 11th, 2004, 10:16 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

There's also anonymous FTP. Create an anonymous FTP account and link to the image using an FTP path:
ftp://www.yourdomain.com/path/to/image

If you don't have anonymous FTP capability then a server-side language is the best solution.

PHP:
Code:
<?php
    header("Content-type: image/jpeg");
    header("Content-Disposition: attachment; filename=proposedFileName.jpg");
    readfile('image.jpg');
?>
ASP:
Code:
Dim sFullFileName
sFullFileName = "C:\image\path\image.jpg"

Response.Contenttype="image/jpeg"
Response.Addheader "Content-Disposition", "attachment; filename=" & chr(34) & sFileName & chr(34)
Response.Binarywrite GetBinaryFile(sFullFileName)

Function GetBinaryFile(ByVal sFileSpec)
         Const adTypeBinary = 1
         Dim objStream
         Set objStream = Server.Createobject("ADODB.Stream")
         objStream.Open
         objStream.Type = adTypeBinary
         objStream.LoadFromFile sFileSpec
         GetBinaryFile = objStream.read
         Set objStream = Nothing
End Function
I don't know which version of ASP this is.. I lifted the code from one of Imar's replies.

HTH!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old July 12th, 2004, 02:42 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:I don't know which version of ASP this is..
This will work in all ASP versions. However, the Stream object was introduced in ADO version 2.5 so you'll need that installed on your server.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: I Will by Radiohead (Track 10 from the album: Hail To The Thief) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Download in Image from Sql Server 2000 using asp surendraparashar Classic ASP Basics 0 December 16th, 2007 11:55 PM
download data ("image") from SQL database problems alex9183 Classic ASP Databases 2 September 14th, 2006 09:02 AM
download data ("image") from SQL database problems dcleslie Classic ASP Databases 9 August 29th, 2006 01:10 PM
Smaller download/single download file available jminatel BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 November 21st, 2005 11:10 AM
download text or image from web page cjursch Javascript How-To 1 June 12th, 2003 12:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.