SyncViews Posted January 4, 2008 Share Posted January 4, 2008 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 More sharing options...
mike1313 Posted January 4, 2008 Share Posted January 4, 2008 That may go beyond a simple <a>. Link to comment https://forums.phpfreaks.com/topic/84490-downloading-instead-of-viewing-file/#findComment-430478 Share on other sites More sharing options...
Northern Flame Posted January 5, 2008 Share Posted January 5, 2008 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 https://forums.phpfreaks.com/topic/84490-downloading-instead-of-viewing-file/#findComment-430929 Share on other sites More sharing options...
SyncViews Posted January 5, 2008 Author Share Posted January 5, 2008 Oh I see...so I can't just link directly and have it download... Link to comment https://forums.phpfreaks.com/topic/84490-downloading-instead-of-viewing-file/#findComment-431355 Share on other sites More sharing options...
Northern Flame Posted January 9, 2008 Share Posted January 9, 2008 not that I know of.... Link to comment https://forums.phpfreaks.com/topic/84490-downloading-instead-of-viewing-file/#findComment-434135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.