0

I have a wapsite where I am implementing forceful download.

The script is in PHP

It works great for all the other mobile browsers, but when I access the site using Android phone, it downloads the actual PHP file.

Following is my code snippet of file downloadFiles.php.

$fileExt = "jpg";
$strOrgFileName = "abc.jpg";

switch($fileExt) 
{

  case "jpeg":

  case "jpg": $ctype="image/jpg"; break;

  case "gif": $ctype="image/gif"; break;

  case "png": $ctype="image/png"; break;

  case "zip": $ctype="application/zip"; break;

  default: $ctype="application/force-download";

}

header("Pragma: public");

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Content-Type: $ctype");

header("Content-Description: File Transfer");

header("Content-Disposition: attachment; filename=\"".$strOrgFileName."\";" );

readfile($strOrgFileName);

In Android system it downloads the PHP file.

i.e. downloadFiles.php

Dharman
  • 30,962
  • 25
  • 85
  • 135
dirtycode
  • 63
  • 1
  • 10

2 Answers2

0

The ONLY way that anything should be able to download your .php source files is if your web server has some kind of misconfiguration. If other php is working via android, perhaps something in android and this file is causing the whole server to stumble and barf... But that should bring down the entire server, not simply dump the file.

Am I also missing something? This is quite the puzzle...

DampeS8N
  • 3,621
  • 17
  • 20
  • even m confuzzed. the entire wap version works perfect but when I click on the download link, it just downloads the file. I guess there is some headers issue, but I couldn't find anything on net. So that means php is working fine. may be theres some hookup in my script which i just couldn't find... – dirtycode Nov 17 '10 at 15:39
  • It almost has to be something that is causing either the script to sub itself for the output, or something wrong with the server that is telling the download to download the file not to process the file and download the result... Maybe you've stumbled on a new way to hack a server? What flavor of server are you using? Apache? – DampeS8N Nov 17 '10 at 16:56
  • yup m using Apache/2.2.3 CentOS with PHP Version 5.2.12 – dirtycode Nov 18 '10 at 06:55
  • actually the image file is getting downloaded with the name of PHP processing file ie. downloadFiles.php Can anybody help me with this. – dirtycode Nov 19 '10 at 13:40
  • So it isn't downloading the php? That's quite a different thing. One solution would be to call it the correct name and set your server to process files of that type as php. – DampeS8N Nov 21 '10 at 02:00
0

To make any downloads work on all (and especially older) Android versions as expected, you need to...

  1. set the ContentType to application/octet-stream
  2. put the Content-Disposition filename value in double quotes
  3. write the Content-Disposition filename extension in UPPERCASE

Read my blog post for more details:
http://digiblog.de/2011/04/19/android-and-the-download-file-headers/

Cheers, Jpsy.

Jpsy
  • 20,077
  • 7
  • 118
  • 115