-1

i was trying to download from an android application a php file stored onto my server.

From the application i call a webservices that have to give me in output the file .php that i need.

On the web i found this that talk about which header set to download a file. It talks about

  • zip
  • jpg
  • txt
  • pdf

Then i was thinking to develop something like:

  1. Application call ws to get a php page
  2. Ws zips the php file that application needs and give me in putput
  3. Application download the zip file and extract it.

This is a good solution but i was trying to find something better.

Another solution that is really like what i want is highlight_file

Just use it like:

echo highlight_file("myphpfile.php");

The problem is that in order to render good the file, the code is divided by many html tags and just "visually" is the same file but the source is really different.

Is there a way to download the file directly? Thanks! :)

Jayyrus
  • 12,961
  • 41
  • 132
  • 214
  • 1
    http://stackoverflow.com/questions/9948178/php-file-force-download - http://stackoverflow.com/questions/3314579/php-force-download-to-hd - http://stackoverflow.com/questions/4706073/php-force-download-causing-0-byte-files - http://stackoverflow.com/questions/13654890/php-force-download-header-wont-show-total-size-and-speed - http://stackoverflow.com/questions/2106709/forcing-page-download-in-php - http://stackoverflow.com/questions/11266281/php-forcing-a-download-not-working – Mike B Mar 26 '13 at 16:03

1 Answers1

3

The simplest solution might be:

<?php

header('Content-Type: text/plain');
readfile("myphpfile.php");

this will display the file as text in browser you can click 'save as...'

If you need the browser to popup a 'Save as...' dialog by itself - without displaying the file - then you'll need the Content-Disposition header:

header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="myphpfile.php"');

readfile("myphpfile.php");
hek2mgl
  • 152,036
  • 28
  • 249
  • 266