[FX.php List] [OFF] connection_aborted on IIS
Dale Bengston
dbengston at tds.net
Tue Dec 15 09:30:08 MST 2009
I'm out of my pay grade when it comes to web servers and their log files. I have gone as far as logging the user's intent to download something, but I am not capturing success or failure of the actual transmission.
Hmm, well, turning my Speculator on full-blast, I'll give it a try: I'm not sure once the download is handed off to the browser that it's possible to log success or failure. You could capture the success of initiating a download, but after that it's the user's browser driving things.
Also, I'm not sure how you'd capture a connection failure. If the user quits the browser in the middle of the download, does that look the same to a web server as a connection failure due to squirrels gnawing on one's wires?*
Anyone else have experience with this?
Dale
* This actually happened to me.
On Dec 15, 2009, at 8:34 AM, Someone wrote:
> Hi Dale,
> What happens if the internet goes down in the middle of a download, how do you capture this and log it.
>
> On Dec 14, 2009, at 8:48 PM, Dale Bengston wrote:
>
>> I'm not sure I understand your question.
>>
>> On Dec 14, 2009, at 2:45 PM, Someone wrote:
>>
>>> Hi Dale,
>>> Where do you your database action if download is successful
>>>
>>> On Dec 14, 2009, at 2:11 PM, Dale Bengston wrote:
>>>
>>>> Hi Frank,
>>>>
>>>> Here's how I force a download x-plat. Content type doesn't matter. You want the browser to think it's not something it can load in a browser window.
>>>>
>>>> header('Content-Description: File Transfer');
>>>> header('Content-Type: application/octet-stream');
>>>> header('Content-Disposition: attachment; filename='. basename($file));
>>>> header('Content-Transfer-Encoding: binary');
>>>> header('Expires: 0');
>>>> header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
>>>> header('Pragma: public');
>>>> header('Content-Length:' . filesize($file));
>>>> ob_clean();
>>>> flush();
>>>> readfile($file);
>>>> exit;
>>>>
>>>> I have not tried it on .exe files. That might be a security thing that IIS is preventing.
>>>>
>>>> Dale
>>>>
>>>>
>>>> On Dec 14, 2009, at 9:38 AM, Someone wrote:
>>>>
>>>>> Hi,
>>>>> Does any one know if connection_aborted function works on IIS (Microsoft-IIS/7.0) / Windows Server 2008
>>>>>
>>>>> I'm trying to do a force down a file (exe) and record if download was completed
>>>>>
>>>>> It works on Apache/ OS X
>>>>>
>>>>> Thanks
>>>>> Frank
>>>>>
>>>>> Here's the script
>>>>> ---------------------------------------------------
>>>>> $filename = $_GET['file'];
>>>>>
>>>>> // required for IE, otherwise Content-disposition is ignored
>>>>> if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');
>>>>>
>>>>> $file_extension = strtolower(substr(strrchr($filename,"."),1));
>>>>>
>>>>> if( $filename == "" ) {
>>>>> //echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
>>>>> exit;
>>>>> } elseif ( ! file_exists( $filename ) ) {
>>>>> //echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>";
>>>>> exit;
>>>>> };
>>>>> switch( $file_extension )
>>>>> {
>>>>> case "pdf": $ctype="application/pdf"; break;
>>>>> case "exe": $ctype="application/octet-stream"; break;
>>>>> case "zip": $ctype="application/zip"; break;
>>>>> case "doc": $ctype="application/msword"; break;
>>>>> case "xls": $ctype="application/vnd.ms-excel"; break;
>>>>> case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
>>>>> case "gif": $ctype="image/gif"; break;
>>>>> case "png": $ctype="image/png"; break;
>>>>> case "jpeg":
>>>>> case "jpg": $ctype="image/jpg"; break;
>>>>> default: $ctype="application/force-download";
>>>>> }
>>>>>
>>>>> 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: $ctype");
>>>>> // change, added quotes to allow spaces in filenames, by Rajkumar Singh
>>>>> header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
>>>>> header("Content-Transfer-Encoding: binary");
>>>>> header("Content-Length: ".filesize($filename));
>>>>>
>>>>> $bytes_send = 0;
>>>>> $size = filesize($filename);
>>>>> $file = fopen($filename,"rb");
>>>>> if(isset($_SERVER['HTTP_RANGE'])) fseek($file, $range);
>>>>> while(!feof($file) ){ // if we haven't got to the End Of File
>>>>> $buffer = fread($file, 1024*8);
>>>>> print($buffer);//read 8k from the file and send to the user
>>>>> flush();//force the previous line to send its info
>>>>> $bytes_send += strlen($buffer);
>>>>> if (connection_aborted()){ //check the connection, if it has ended...
>>>>> fclose($file);//close the file
>>>>> die(); //kill the script
>>>>> }
>>>>> }
>>>>> if( connection_aborted() ) die();
>>>>>
>>>>> fclose($file);//close the file
>>>>>
>>>>> if( $size == $bytes_send){
>>>>> // record download was completed
>>>>> }
>>>>> exit;
>>>>> ---------------------------------------------------
>>>>> _______________________________________________
>>>>> FX.php_List mailing list
>>>>> FX.php_List at mail.iviking.org
>>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list