I've searched here on StackOverflow and search through Google, unfortunatelly nowhere I can find an answer.
I'm trying to get the content-length of a file I'm downloading to the android app through "openConnection". File is downloading OK, but I want a progress bar which follows the progress.
In order to get that, I need to get the content-length.
The headers I have in my PHP file are:
$file_url = 'myfile.pdf';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header('Content-Length: '.filesize($file_url));
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
readfile($file_url);
Upon a HTTP Header check online I get this:
HTTP/1.1 200 OK =>
Date => Thu, 24 Jul 2014 10:34:04 GMT
Server => Apache/2
X-Powered-By => PHP/5.3.28
Content-Transfer-Encoding => Binary
Content-disposition => attachment; filename="myile.pdf"
Content-Length => 19011079
Vary => Accept-Encoding,User-Agent
Connection => close
Content-Type => application/octet-stream
So it DOES return the content length.
During the whole process the fileSize int keeps being on -1, but the file is downloaded properly into my download directory, so that's not the problem.
Now for the strange bit, when I'm setting it directly to a JPG it DOES return the "Content-Length". Here are the headers for the JPG
HTTP/1.1 200 OK =>
Date => Thu, 24 Jul 2014 10:51:21 GMT
Server => Apache/2
Last-Modified => Thu, 24 Jul 2014 10:23:40 GMT
ETag => "506eae-10fcec-4feedd9b40300"
Accept-Ranges => bytes
Content-Length => 1113324
Connection => close
Content-Type => image/jpeg
Other things I've tried was directly linking to the PDF, which also did not return a Content-Length. I've tried uploading smaller PDF's, in the range of the JPG size also, which was unsuccessful.