NikkiLoveGod Posted February 2, 2008 Share Posted February 2, 2008 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 Link to comment https://forums.phpfreaks.com/topic/89099-solved-a-script-sending-a-php-file-for-user/ Share on other sites More sharing options...
NikkiLoveGod Posted February 3, 2008 Author Share Posted February 3, 2008 EDIT: oops, looks like it kinda fucked up the message, when I tried to put a example code ( 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 Link to comment https://forums.phpfreaks.com/topic/89099-solved-a-script-sending-a-php-file-for-user/#findComment-456594 Share on other sites More sharing options...
Cagecrawler Posted February 3, 2008 Share Posted February 3, 2008 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/ Link to comment https://forums.phpfreaks.com/topic/89099-solved-a-script-sending-a-php-file-for-user/#findComment-456609 Share on other sites More sharing options...
NikkiLoveGod Posted February 3, 2008 Author Share Posted February 3, 2008 Yea! Thanks 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! Link to comment https://forums.phpfreaks.com/topic/89099-solved-a-script-sending-a-php-file-for-user/#findComment-456612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.