Hi there pps

I sincerely hope one of you boffins can help me. I am sure it's quite easy to do, but I am relatively new to web designing.

My question: What html code can I use - when somebody clicks on an image link, it doesnt open the image, but it DOWLOADS to the person's chosen directory?

If it will help - I am using Dreamweaver CS4/3

Thanks,

Dani AI

Generated

Quick summary and practical options based on the thread: is right that users can save an image themselves, but for a cleaner UI there are two practical approaches: a simple client-side anchor with the HTML5 download attribute, or a server-side download endpoint that sets the response so the browser treats the file as an attachment.

A minimal client-side option (works best for same-origin files and modern browsers):

<a href="/images/photo.jpg" download>Download photo</a>

See the HTML5 download attribute documentation for browser behavior and limitations: download attribute.

For a reliable, cross-browser solution (and to control access), use a server script as suggested by but follow secure practices: never accept raw file paths from the user, map a short ID or token to a filename stored outside the web root, validate against a whitelist, set an appropriate MIME type and a download disposition header so the browser treats the response as an attachment, then stream the file or delegate to the webserver for delivery. Protect against path traversal and other file access issues (OWASP guidance): . For header details see: Content-Disposition header.

Recommended workflow for : use the download anchor for simple public files; implement the server-side pattern with strict validation when you need to force a download, control access, or support older browsers.

Recommended Answers

All 3 Replies

You don't. The user does this.

The user right-clicks on the image, and selects Save Image As from the menu.

It would be a security violation if a web page did this on its own.

Hi, I dont think it would be a security violation if you create a link to download an image. I am just trying to move away from having to write on the webpage 'Right click on link and select "save target as"' - it doesnt look nice, and I dont have the space on the page.

in html I dunno
in php I use a link to a force download script <a href=download.php?file=filename&type=filetype> it does not check for filetypes etc, because i code the link

<?php if(!$file) return false;
header("content-disposition: attachment; filename=$file");
header("content-type: $type;");
readfile("$file"); ?>

there might be need to sanitize the code to prevent someone getting other files off your site http://www.yoursite.com/download.php%3Ffile%3Ddownload.php%26type%3Dtext%2Fphp works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.