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
https://forums.phpfreaks.com/topic/84490-downloading-instead-of-viewing-file/
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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.