I am trying to export data from back-end using a PHP script (download.php).
A folder path issue has been kept me stuck as described in following cases :
Running my site on a sub-domain : softy.foo.com
Script file which executes on user clicking the export button :
download.php (Path : public_html/softy/warehouse/items/download.php)
Case 1 :
Created exportedfiles folder in same location as of download.php i.e. items/exportedfiles - RESULT : file downloads successfully
Case 2 :
Created exportedfiles folder outside items directory - RESULT : file downloads successfully
Case 3 :
Created exportedfiles folder in extreme outside path. i.e. inside public_html folder and I gave full path to readfile() as param - RESULT : file download fails -
The file first proceeds whole downloading in the Chrome downloads but at last when download completes it says :
Failed - Network error
(The above error appears in the Chrome downloads bar along with the size of file ex. : 31 KB)
download.php reads as below :
$FileName = 'itemlist.xls';
$Path = 'exportedfiles/'; //works
$Path = '../exportedfiles/'; //works
$Path = '/mydrive/foo/public_html/softy/exportedfiles/'; //fails
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: application/msexcel");
header("Content-Disposition: attachment; filename=\"{$FileName}\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($Path.$FileName)) ;
readfile($Path."{$FileName}");