FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Force Downloading.





Dougie1
Is there a way to force download php files? I know how to do this with pdfs and things but php files do not seem to work in the same way. They download but have no content.

Thanks.
Smile
MrBlueSky
Do you mean downloading PHP source code from a site? That's not possible (except if they want to allow it explicitly or the server is badly configured). Before you get the file all the PHP is already executed by the server, and what you get is the output of the PHP script.
hexkid
Dougie1 wrote:
Is there a way to force download php files? I know how to do this with pdfs and things but php files do not seem to work in the same way. They download but have no content.


This works for me
Code:
<?php
header('Content-Type: application/octet-stream; charset=us-ascii');
// must use substr(<PHP_SELF>, 1) to remove leading slash
header('Content-Disposition: attachment; filename="' . substr($_SERVER['PHP_SELF'], 1) . '"');
readfile(substr($_SERVER['PHP_SELF'], 1));
?>


[Edit:] Try the script in the root directory of your site.
Rhysige
Why do you want to force the file download?
Scorpio
Dougie1 wrote:
Is there a way to force download php files? I know how to do this with pdfs and things but php files do not seem to work in the same way. They download but have no content.

Thanks.
Smile


Do you actually want to download certain PHP files from sites?

I was actually wondering if there is a method to download a php file from any particular site like www.xyz.com/index.php [which is not my site] or something like that.

I am not very familiar with PHP, hexkid, but can your code do the above operation?
hexkid
scorpio wrote:
I was actually wondering if there is a method to download a php file from any particular site like www.xyz.com/index.php [which is not my site] or something like that.

I am not very familiar with PHP, hexkid, but can your code do the above operation?
No. It is impossible to download a php file if you don't control the server that php file is in.

My example above, is to download a php file on a server where you can create php scripts.
ninjakannon
hexkid wrote:
I am not very familiar with PHP, hexkid, but can your code do the above operation?
No. It is impossible to download a php file if you don't control the server that php file is in.[/quote]
I've tried to do this too but never succeeded; I was trying to come up with some method which wouldn't involve running the file, but there really isn't one. Just now I tried opened a php file on my website in notepad (by typing in the direct link into the File name box in the Open window) and it still - obviously - returned the output of the file.
manum
nup it's impossible as the code runs on server and gives html output which is sent back to the browser by the server unlike java scripts where the code is run on the clients computer..........
Related topics
Downloading the Internet!
What is your graphics card?
Does downloading and uploading from ftp client use bandwith?
UN food force
ATI X1800
Star Trek Voyage Elite Force
Is downloading movies legal if...
Hong Kong: young man has been jailed for files sharing
Illegal Downloading, Serious Discussion
phpBB2 - Installing Templates/Skins
Downloading Backups
Freedom Force for the NES
GETTING BACK DONATED POINTS BY FORCE
Force Downloading From Another Server bandwidth issues?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.