Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17444
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2012-12-03 16:14 -0800 |
| Message-ID | <74b314b0-3138-4fdf-b31e-bc7c9b1dbcba@googlegroups.com> (permalink) |
| Subject | Ajax Call to PHP Download.php Makes Browser Not Download, But Client Still Receives Stream |
| From | dman777 <darin.hensley@gmail.com> |
This script is for my http file server. I have my files out of web root, so I am using a php script to grab and send the files to the client. The problem is, when I click on the file to download the browser(ff and chrome) does not ask me if I want to save the file. In chrome's web tools, under network, I see that the download.php did execute successfully. In fact, I even see where the file was transfered in bytes for the request. It seems like the browser is not downloading the file, but the file is being sent to the browser and cached.
Web server is Nginx.
This goes for any type of file. I tried text file, mp3, and zip.
I must emphasis that THE FILE IS BEING SENT TO THE BROWSER. I verified it in chromes network tab for bytes transferred. But for some reason, the file is not being saved on the client computer,the browser does ask to save file, and the browser does not have a record of the downloaded file.
I have verified this script works on other web servers. I also verified other another http file server nginx user does not have this issue(using php). So, therefore I think it maybe because I am calling it with ajax.
<?php
$path = "/trunk/";
$file = $_POST['filename'];
$file_ext = pathinfo($file, PATHINFO_EXTENSION);
$file_name = pathinfo($file, PATHINFO_BASENAME);
$file_full = $path . $file_name;
$finfo = new finfo(FILEINFO_MIME_TYPE);
$ctype = $finfo -> file($file_full);
header("Content-Disposition: attachment; filename=\"".$file_name."\"");
header("Content-Type: " .$ctype);
header("Content-Length: " .filesize($file_full));
error_log(filesize($file_full));
readfile($file_full);
?>
Request Header:
POST /php/download.php HTTP/1.1
Host: www.example.com
Connection: keep-alive
Content-Length: 146
Origin: https://www.example.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryMA7u5AkYPL9qGmRY
Accept: */*
Referer: https://www.example.com/index.php
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
RESPONSE HEADER
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 01 Dec 2012 20:22:28 GMT
Content-Type: application/zip
Content-Length: 75090
Connection: keep-alive
Keep-Alive: timeout=300
X-Powered-By: PHP/5.4.6--pl0-gentoo
Content-Disposition: attachment; filename="try.zip"
Expires: Sat, 01 Dec 2012 20:22:27 GMT
Cache-Control: no-cache
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
Ajax Call to PHP Download.php Makes Browser Not Download, But Client Still Receives Stream dman777 <darin.hensley@gmail.com> - 2012-12-03 16:14 -0800
Re: Ajax Call to PHP Download.php Makes Browser Not Download, But Client Still Receives Stream dman777 <darin.hensley@gmail.com> - 2012-12-03 16:16 -0800
Re: Ajax Call to PHP Download.php Makes Browser Not Download, But Client Still Receives Stream Denis McMahon <denismfmcmahon@gmail.com> - 2012-12-04 00:48 +0000
csiph-web