Jump to content

[SOLVED] A script sending a .php file for user?


NikkiLoveGod

Recommended Posts

Hi everyone!

 

Im having a little problem here, I am making a simple script here, that just lists the files in a folder, makes them a link and when the user clicks the link, he SHOULD be getting a download prompt for a .php file, but that is what im having a problem here. Of course it is trying to redirect the browser to a .php file, when it is just a simple <a href="http://xxx.com/xxx/example.php">. Im thinking this has something to do with either server settings, or headers, prolly headers.

 

So any ideas, how can I make it so that when I press the link, it will download the php file, instead of redirecting? Its a little hard subject to try and google it :S

 

Thanks!

-NikkiLoveGod

EDIT: oops, looks like it kinda fucked up the message, when I tried to put a example code :D ( AND BUMP )

 

Hi everyone!

 

Im having a little problem here, I am making a simple script here, that just lists the files in a folder, makes them a link and when the user clicks the link, he SHOULD be getting a download prompt for a .php file, but that is what im having a problem here. Of course it is trying to redirect the browser to a .php file, when it is just a simple < a href="test.php>. Im thinking this has something to do with headers.

 

So any ideas, how can I make it so that when I press the link, it will download the php file, instead of redirecting? Its a little hard subject to try and google it, since i cant really figure out any keywords :S

 

BTW: as a reference, it is done in phpclasses.org !

 

Thanks!

-NikkiLoveGod

Create a download page which calls the file you want and does a force download (ie. download.php?file=example.php).  Make sure to include relevent checks to stop XSS.  To force a download, I think its "Content-Disposition: attachment" is what's needed.

 

Quick google example: http://www.phpit.net/code/force-download/

Yea! Thanks :D I found one my self too! heres the one I found my self which allows for download. I need to put up some code to stop some lamers.

 

<?php
$file = "backup.php";
header('Content-Type: Application/Octet-Stream');
header('Content-Disposition: Attachment; Filename="backup.php"');
readfile("backup.php");
?>

 

btw, it seems that the capitalization of the words are very importat, so that the files arent corrupted!

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.