On the server side, get progress when sending the file

Basically, I want to check how many files my web server sent to the client when the client downloads it. Is it possible? Does apache provide any module / extension that would help me complete my task?

I am using linux distribution, apache2 and php5. Best wishes.

0
file php apache fopen progress
source share
2 answers

I decided.

I just open a file with PHP that I want to send to the client.

$fh = fopen($filePath, 'r'); 

Then I calculate 60% of the file size by writing

 $fileSize = filesize($filePath); $sizeFirst = floor(($fileSize / 100) * 60); 

Now the $ sizeFirst variable contains the length of the first 60% of the file in a numerical value. To calculate the remaining 40%, I use:

 $sizeLast = $fileSize - $sizeFirst; 

Now I can record the first 60%, perform my action, and then write outh the remaining 40%.

 $dataFirst = fread($fh, $sizeFirst); echo($dataDirst); // Do my action here. $dataSecond = fread($fh, $sizeSecond); echo($dataSecond); exit(); 

I need to set header (); Before displaying this, you must specify Content-length, Content-type and Content-Disposition in order to send the client a valid header and file.

Hope this helps someone.

0
source share

The browser provides this function if the file has the correct "Content-length" header. Why do you want to implement this on your page?

0
source share

All Articles