Jump to content

Downloading instead of viewing file


SyncViews

Recommended Posts

How do I get it so that people download a file rather than viewing it when useing a certain link?

 

eg. <a href="images/picture.png">Download:</a>

 

Instead of the picture being downloaded the brower will just open it :(

 

I looked to see if there was something like action="download" for the <a> element but it seems that there isn't :(

Link to comment
Share on other sites

you can do it with php

 

<?php

$saveName = stripslashes($_GET["name"]);
$savePath = stripslashes($_GET["path"]);

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$saveName");
header("Content-Transfer-Encoding: binary");

header("Content-length: " . filesize($savePath));

readfile($savePath);

?>

 

then just put

<a href="download.php?name=picture.png&path=images/picture.png">Download Picture</a>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.