IE 'hangs' when I try to display an uploaded file

This is a discussion on IE 'hangs' when I try to display an uploaded file within the PHP Language forums, part of the PHP Programming Forums category; Hi I currently have a site where users can upload files. These files can be doc, wmv, jpeg, xls, dwf, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-14-2008
tomhawkins1@gmail.com
 
Posts: n/a
Default IE 'hangs' when I try to display an uploaded file

Hi

I currently have a site where users can upload files. These files can
be doc, wmv, jpeg, xls, dwf, dwf and dwg.

These files are uploaded to /home/**user**/uploads and not /home/
**user**/public_html/uploads to prevent any old user from browsing
them.

I then use a general showDoc page with the following function (from
php.net)

function readfile_chunked($filename,$retbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;

}


which is called here

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: inline; filename=
\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile_chunked("$filename");
exit();

Now, if I have a file of more than about 3MB (tried with a wmv and
dxf), it won't show, and my whole site becomes unresponsive to any
input until I close the browser, open IE again and log in again.
filename and ctype must be being passed correctly but the size of the
file seems to make it hang. I have succeded in uploading files of up
to 15MB but the larger ones won't display!

Any ideas?

TomH
Reply With Quote
  #2 (permalink)  
Old 06-14-2008
tomhawkins1@gmail.com
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

On Jun 14, 11:19*am, tomhawki...@gmail.com wrote:
> Hi
>
> I currently have a site where users can upload files. These files can
> be doc, wmv, jpeg, xls, dwf, dwf and dwg.
>
> These files are uploaded to /home/**user**/uploads and not /home/
> **user**/public_html/uploads to prevent any old user from browsing
> them.
>
> I then use a general showDoc page with the following function (from
> php.net)
>
> function readfile_chunked($filename,$retbytes=true) {
> * * * * * * * * $chunksize = 1*(1024*1024); // how many bytes per chunk
> * * * * * * * * $buffer = '';
> * * * * * * * * $cnt =0;
> * * * * * * * * // $handle = fopen($filename, 'rb');
> * * * * * * * * $handle = fopen($filename, 'rb');
> * * * * * * * * if ($handle === false) {
> * * * * * * * * * * * * return false;
> * * * * * * * * }
> * * * * * * * * while (!feof($handle)) {
> * * * * * * * * * * * * $buffer = fread($handle,$chunksize);
> * * * * * * * * * * * * echo $buffer;
> * * * * * * * * * * * * ob_flush();
> * * * * * * * * * * * * flush();
> * * * * * * * * * * * * if ($retbytes) {
> * * * * * * * * * * * * * * * * $cnt += strlen($buffer);
> * * * * * * * * * * * * }
> * * * * * * * * }
> * * * * * * * * $status = fclose($handle);
> * * * * * * * * if ($retbytes && $status) {
> * * * * * * * * * * * * return $cnt; // return num.. bytes delivered like readfile() does.
> * * * * * * * * }
> * * * * * * * * return $status;
>
> * * * * }
>
> which is called here
>
> * * * * header("Pragma: public");
> * * * * header("Expires: 0");
> * * * * header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> * * * * header("Cache-Control: private",false);
> * * * * header("Content-Type: $ctype");
> * * * * header("Content-Disposition: inline; filename=
> \"".basename($filename)."\";" );
> * * * * header("Content-Transfer-Encoding: binary");
> * * * * header("Content-Length: ".filesize($filename));
> * * * * readfile_chunked("$filename");
> * * * * exit();
>
> Now, if I have a file of more than about 3MB (tried with a wmv and
> dxf), it won't show, and my whole site becomes unresponsive to any
> input until I close the browser, open IE again and log in again.
> filename and ctype must be being passed correctly but the size of the
> file seems to make it hang. I have succeded in uploading files of up
> to 15MB but the larger ones won't display!
>
> Any ideas?
>
> TomH



A quick update. If I right click the link and save target as, the
files download perfectly but I want to display, not download them. Two
things happen though. No other link on the site will work until the
file has finished downloading. Secondly, it I cancel the download
before it completes, the same 'hang' happens and I have to close and
reopen the browser.

TomH.
Reply With Quote
  #3 (permalink)  
Old 06-14-2008
Jerry Stuckle
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

tomhawkins1@gmail.com wrote:
> On Jun 14, 11:19 am, tomhawki...@gmail.com wrote:
>> Hi
>>
>> I currently have a site where users can upload files. These files can
>> be doc, wmv, jpeg, xls, dwf, dwf and dwg.
>>
>> These files are uploaded to /home/**user**/uploads and not /home/
>> **user**/public_html/uploads to prevent any old user from browsing
>> them.
>>
>> I then use a general showDoc page with the following function (from
>> php.net)
>>
>> function readfile_chunked($filename,$retbytes=true) {
>> $chunksize = 1*(1024*1024); // how many bytes per chunk
>> $buffer = '';
>> $cnt =0;
>> // $handle = fopen($filename, 'rb');
>> $handle = fopen($filename, 'rb');
>> if ($handle === false) {
>> return false;
>> }
>> while (!feof($handle)) {
>> $buffer = fread($handle, $chunksize);
>> echo $buffer;
>> ob_flush();
>> flush();
>> if ($retbytes) {
>> $cnt += strlen($buffer);
>> }
>> }
>> $status = fclose($handle);
>> if ($retbytes && $status) {
>> return $cnt; // return num. bytes delivered like readfile() does.
>> }
>> return $status;
>>
>> }
>>
>> which is called here
>>
>> header("Pragma: public");
>> header("Expires: 0");
>> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
>> header("Cache-Control: private",false);
>> header("Content-Type: $ctype");
>> header("Content-Disposition: inline; filename=
>> \"".basename($filename)."\";" );
>> header("Content-Transfer-Encoding: binary");
>> header("Content-Length: ".filesize($filename));
>> readfile_chunked("$filename");
>> exit();
>>
>> Now, if I have a file of more than about 3MB (tried with a wmv and
>> dxf), it won't show, and my whole site becomes unresponsive to any
>> input until I close the browser, open IE again and log in again.
>> filename and ctype must be being passed correctly but the size of the
>> file seems to make it hang. I have succeded in uploading files of up
>> to 15MB but the larger ones won't display!
>>
>> Any ideas?
>>
>> TomH

>
>
> A quick update. If I right click the link and save target as, the
> files download perfectly but I want to display, not download them. Two
> things happen though. No other link on the site will work until the
> file has finished downloading. Secondly, it I cancel the download
> before it completes, the same 'hang' happens and I have to close and
> reopen the browser.
>
> TomH.
>


Try a different browser.

The "no other link on the site will work" can be normal, depending on
how your code is structured. The rest of your problems sound like a
browser problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #4 (permalink)  
Old 06-14-2008
tomhawkins1@gmail.com
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

On Jun 14, 1:09*pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> tomhawki...@gmail.com wrote:
> > On Jun 14, 11:19 am, tomhawki...@gmail.com wrote:
> >> Hi

>
> >> I currently have a site where users can upload files. These files can
> >> be doc, wmv, jpeg, xls, dwf, dwf and dwg.

>
> >> These files are uploaded to /home/**user**/uploads and not /home/
> >> **user**/public_html/uploads to prevent any old user from browsing
> >> them.

>
> >> I then use a general showDoc page with the following function (from
> >> php.net)

>
> >> function readfile_chunked($filename,$retbytes=true) {
> >> * * * * * * * * $chunksize = 1*(1024*1024); // how many bytes per chunk
> >> * * * * * * * * $buffer = '';
> >> * * * * * * * * $cnt =0;
> >> * * * * * * * * // $handle = fopen($filename, 'rb');
> >> * * * * * * * * $handle = fopen($filename, 'rb');
> >> * * * * * * * * if ($handle === false) {
> >> * * * * * * * * * * * * return false;
> >> * * * * * * * * }
> >> * * * * * * * * while (!feof($handle)) {
> >> * * * * * * * * * * * * $buffer = fread($handle, $chunksize);
> >> * * * * * * * * * * * * echo $buffer;
> >> * * * * * * * * * * * * ob_flush();
> >> * * * * * * * * * * * * flush();
> >> * * * * * * * * * * * * if ($retbytes) {
> >> * * * * * * * * * * * * * * * * $cnt += strlen($buffer);
> >> * * * * * * * * * * * * }
> >> * * * * * * * * }
> >> * * * * * * * * $status = fclose($handle);
> >> * * * * * * * * if ($retbytes && $status) {
> >> * * * * * * * * * * * * return $cnt; // return num. bytes delivered like readfile() does.
> >> * * * * * * * * }
> >> * * * * * * * * return $status;

>
> >> * * * * }

>
> >> which is called here

>
> >> * * * * header("Pragma: public");
> >> * * * * header("Expires: 0");
> >> * * * * header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
> >> * * * * header("Cache-Control: private",false);
> >> * * * * header("Content-Type: $ctype");
> >> * * * * header("Content-Disposition: inline; filename=
> >> \"".basename($filename)."\";" );
> >> * * * * header("Content-Transfer-Encoding: binary");
> >> * * * * header("Content-Length: ".filesize($filename));
> >> * * * * readfile_chunked("$filename");
> >> * * * * exit();

>
> >> Now, if I have a file of more than about 3MB (tried with a wmv and
> >> dxf), it won't show, and my whole site becomes unresponsive to any
> >> input until I close the browser, open IE again and log in again.
> >> filename and ctype must be being passed correctly but the size of the
> >> file seems to make it hang. I have succeded in uploading files of up
> >> to 15MB but the larger ones won't display!

>
> >> Any ideas?

>
> >> TomH

>
> > A quick update. If I right click the link and save target as, the
> > files download perfectly but I want to display, not download them. Two
> > things happen though. No other link on the site will work until the
> > file has finished downloading. Secondly, it I cancel the download
> > before it completes, the same 'hang' happens and I have to close and
> > reopen the browser.

>
> > TomH.

>
> Try a different browser.
>
> The "no other link on the site will work" can be normal, depending on
> how your code is structured. *The rest of your problems sound like a
> browser problem.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -


I'll try something else. When you say 'depends on how your code is
structured', short of a mysql query to get the filename, the code is
above. Is there anything in that?

TomH.
Reply With Quote
  #5 (permalink)  
Old 06-14-2008
Jerry Stuckle
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

tomhawkins1@gmail.com wrote:
> On Jun 14, 1:09 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> tomhawki...@gmail.com wrote:
>>> On Jun 14, 11:19 am, tomhawki...@gmail.com wrote:
>>>> Hi
>>>> I currently have a site where users can upload files. These files can
>>>> be doc, wmv, jpeg, xls, dwf, dwf and dwg.
>>>> These files are uploaded to /home/**user**/uploads and not /home/
>>>> **user**/public_html/uploads to prevent any old user from browsing
>>>> them.
>>>> I then use a general showDoc page with the following function (from
>>>> php.net)
>>>> function readfile_chunked($filename,$retbytes=true) {
>>>> $chunksize = 1*(1024*1024); // how many bytes per chunk
>>>> $buffer = '';
>>>> $cnt =0;
>>>> // $handle = fopen($filename, 'rb');
>>>> $handle = fopen($filename, 'rb');
>>>> if ($handle === false) {
>>>> return false;
>>>> }
>>>> while (!feof($handle)) {
>>>> $buffer = fread($handle, $chunksize);
>>>> echo $buffer;
>>>> ob_flush();
>>>> flush();
>>>> if ($retbytes) {
>>>> $cnt += strlen($buffer);
>>>> }
>>>> }
>>>> $status = fclose($handle);
>>>> if ($retbytes && $status) {
>>>> return $cnt; // return num. bytes delivered like readfile() does.
>>>> }
>>>> return $status;
>>>> }
>>>> which is called here
>>>> header("Pragma: public");
>>>> header("Expires: 0");
>>>> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
>>>> header("Cache-Control: private",false);
>>>> header("Content-Type: $ctype");
>>>> header("Content-Disposition: inline; filename=
>>>> \"".basename($filename)."\";" );
>>>> header("Content-Transfer-Encoding: binary");
>>>> header("Content-Length: ".filesize($filename));
>>>> readfile_chunked("$filename");
>>>> exit();
>>>> Now, if I have a file of more than about 3MB (tried with a wmv and
>>>> dxf), it won't show, and my whole site becomes unresponsive to any
>>>> input until I close the browser, open IE again and log in again.
>>>> filename and ctype must be being passed correctly but the size of the
>>>> file seems to make it hang. I have succeded in uploading files of up
>>>> to 15MB but the larger ones won't display!
>>>> Any ideas?
>>>> TomH
>>> A quick update. If I right click the link and save target as, the
>>> files download perfectly but I want to display, not download them. Two
>>> things happen though. No other link on the site will work until the
>>> file has finished downloading. Secondly, it I cancel the download
>>> before it completes, the same 'hang' happens and I have to close and
>>> reopen the browser.
>>> TomH.

>> Try a different browser.
>>
>> The "no other link on the site will work" can be normal, depending on
>> how your code is structured. The rest of your problems sound like a
>> browser problem.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================- Hide quoted text -
>>
>> - Show quoted text -

>
> I'll try something else. When you say 'depends on how your code is
> structured', short of a mysql query to get the filename, the code is
> above. Is there anything in that?
>
> TomH.
>


I'm sure that isn't your entire page. There's a lot more to it. For
instance, sessions are single threaded by PHP. You probably start a
session before the download, and don't close it until the page ends.
During this time, you will not be able to access other pages which use
sessions (but other people can access their pages because they're using
different sessions).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #6 (permalink)  
Old 06-14-2008
tomhawkins1@gmail.com
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

On Jun 14, 1:26*pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> tomhawki...@gmail.com wrote:
> > On Jun 14, 1:09 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >> tomhawki...@gmail.com wrote:
> >>> On Jun 14, 11:19 am, tomhawki...@gmail.com wrote:
> >>>> Hi
> >>>> I currently have a site where users can upload files. These files can
> >>>> be doc, wmv, jpeg, xls, dwf, dwf and dwg.
> >>>> These files are uploaded to /home/**user**/uploads and not /home/
> >>>> **user**/public_html/uploads to prevent any old user from browsing
> >>>> them.
> >>>> I then use a general showDoc page with the following function (from
> >>>> php.net)
> >>>> function readfile_chunked($filename,$retbytes=true) {
> >>>> * * * * * * * * $chunksize = 1*(1024*1024); // how many bytes per chunk
> >>>> * * * * * * * * $buffer = '';
> >>>> * * * * * * * * $cnt =0;
> >>>> * * * * * * * * // $handle = fopen($filename, 'rb');
> >>>> * * * * * * * * $handle = fopen($filename, 'rb');
> >>>> * * * * * * * * if ($handle === false) {
> >>>> * * * * * * * * * * * * return false;
> >>>> * * * * * * * * }
> >>>> * * * * * * * * while (!feof($handle)) {
> >>>> * * * * * * * * * * * * $buffer = fread($handle, $chunksize);
> >>>> * * * * * * * * * * * * echo $buffer;
> >>>> * * * * * * * * * * * * ob_flush();
> >>>> * * * * * * * * * * * * flush();
> >>>> * * * * * * * * * * * * if ($retbytes) {
> >>>> * * * * * * * * * * * * * * * * $cnt += strlen($buffer);
> >>>> * * * * * * * * * * * * }
> >>>> * * * * * * * * }
> >>>> * * * * * * * * $status = fclose($handle);
> >>>> * * * * * * * * if ($retbytes && $status) {
> >>>> * * * * * * * * * * * * return $cnt; // return num. bytes delivered like readfile() does.
> >>>> * * * * * * * * }
> >>>> * * * * * * * * return $status;
> >>>> * * * * }
> >>>> which is called here
> >>>> * * * * header("Pragma: public");
> >>>> * * * * header("Expires: 0");
> >>>> * * * * header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> >>>> * * * * header("Cache-Control: private",false);
> >>>> * * * * header("Content-Type: $ctype");
> >>>> * * * * header("Content-Disposition: inline; filename=
> >>>> \"".basename($filename)."\";" );
> >>>> * * * * header("Content-Transfer-Encoding: binary");
> >>>> * * * * header("Content-Length: ".filesize($filename));
> >>>> * * * * readfile_chunked("$filename");
> >>>> * * * * exit();
> >>>> Now, if I have a file of more than about 3MB (tried with a wmv and
> >>>> dxf), it won't show, and my whole site becomes unresponsive to any
> >>>> input until I close the browser, open IE again and log in again.
> >>>> filename and ctype must be being passed correctly but the size of the
> >>>> file seems to make it hang. I have succeded in uploading files of up
> >>>> to 15MB but the larger ones won't display!
> >>>> Any ideas?
> >>>> TomH
> >>> A quick update. If I right click the link and save target as, the
> >>> files download perfectly but I want to display, not download them. Two
> >>> things happen though. No other link on the site will work until the
> >>> file has finished downloading. Secondly, it I cancel the download
> >>> before it completes, the same 'hang' happens and I have to close and
> >>> reopen the browser.
> >>> TomH.
> >> Try a different browser.

>
> >> The "no other link on the site will work" can be normal, depending on
> >> how your code is structured. *The rest of your problems sound like a
> >> browser problem.

>
> >> --
> >> ==================
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck...@attglobal.net
> >> ==================- Hide quoted text -

>
> >> - Show quoted text -

>
> > I'll try something else. When you say 'depends on how your code is
> > structured', short of a mysql query to get the filename, the code is
> > above. Is there anything in that?

>
> > TomH.

>
> I'm sure that isn't your entire page. *There's a lot more to it. *For
> instance, sessions are single threaded by PHP. *You probably start a
> session before the download, and don't close it until the page ends.
> During this time, you will not be able to access other pages which use
> sessions (but other people can access their pages because they're using
> different sessions).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -


I see. That's true.

Here's the structure then.
Show Doc.
Include functions file (which has session_start()) at the top in
addition to connections to mysql.
Perform mysql query using GET vars and SESSION vars.
Determine the filename I want to display.
readfile_chunked the file.

From what you say, unless the page ends, the session will be
'locked'. If I pass the session variables via GET instead and close
the session as the 2nd line of showdoc.php (1st line includes the file
which starts the session) before I get the filename data and display
it, will that work?
TomH.
Reply With Quote
  #7 (permalink)  
Old 06-14-2008
Jerry Stuckle
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

tomhawkins1@gmail.com wrote:
> On Jun 14, 1:26 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> tomhawki...@gmail.com wrote:
>>> On Jun 14, 1:09 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>>> tomhawki...@gmail.com wrote:
>>>>> On Jun 14, 11:19 am, tomhawki...@gmail.com wrote:
>>>>>> Hi
>>>>>> I currently have a site where users can upload files. These files can
>>>>>> be doc, wmv, jpeg, xls, dwf, dwf and dwg.
>>>>>> These files are uploaded to /home/**user**/uploads and not /home/
>>>>>> **user**/public_html/uploads to prevent any old user from browsing
>>>>>> them.
>>>>>> I then use a general showDoc page with the following function (from
>>>>>> php.net)
>>>>>> function readfile_chunked($filename,$retbytes=true) {
>>>>>> $chunksize = 1*(1024*1024); // how many bytes per chunk
>>>>>> $buffer = '';
>>>>>> $cnt =0;
>>>>>> // $handle = fopen($filename, 'rb');
>>>>>> $handle = fopen($filename, 'rb');
>>>>>> if ($handle === false) {
>>>>>> return false;
>>>>>> }
>>>>>> while (!feof($handle)) {
>>>>>> $buffer = fread($handle, $chunksize);
>>>>>> echo $buffer;
>>>>>> ob_flush();
>>>>>> flush();
>>>>>> if ($retbytes) {
>>>>>> $cnt += strlen($buffer);
>>>>>> }
>>>>>> }
>>>>>> $status = fclose($handle);
>>>>>> if ($retbytes && $status) {
>>>>>> return $cnt; // return num. bytes delivered like readfile() does.
>>>>>> }
>>>>>> return $status;
>>>>>> }
>>>>>> which is called here
>>>>>> header("Pragma: public");
>>>>>> header("Expires: 0");
>>>>>> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
>>>>>> header("Cache-Control: private",false);
>>>>>> header("Content-Type: $ctype");
>>>>>> header("Content-Disposition: inline; filename=
>>>>>> \"".basename($filename)."\";" );
>>>>>> header("Content-Transfer-Encoding: binary");
>>>>>> header("Content-Length: ".filesize($filename));
>>>>>> readfile_chunked("$filename");
>>>>>> exit();
>>>>>> Now, if I have a file of more than about 3MB (tried with a wmv and
>>>>>> dxf), it won't show, and my whole site becomes unresponsive to any
>>>>>> input until I close the browser, open IE again and log in again.
>>>>>> filename and ctype must be being passed correctly but the size of the
>>>>>> file seems to make it hang. I have succeded in uploading files of up
>>>>>> to 15MB but the larger ones won't display!
>>>>>> Any ideas?
>>>>>> TomH
>>>>> A quick update. If I right click the link and save target as, the
>>>>> files download perfectly but I want to display, not download them. Two
>>>>> things happen though. No other link on the site will work until the
>>>>> file has finished downloading. Secondly, it I cancel the download
>>>>> before it completes, the same 'hang' happens and I have to close and
>>>>> reopen the browser.
>>>>> TomH.
>>>> Try a different browser.
>>>> The "no other link on the site will work" can be normal, depending on
>>>> how your code is structured. The rest of your problems sound like a
>>>> browser problem.
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================- Hide quoted text -
>>>> - Show quoted text -
>>> I'll try something else. When you say 'depends on how your code is
>>> structured', short of a mysql query to get the filename, the code is
>>> above. Is there anything in that?
>>> TomH.

>> I'm sure that isn't your entire page. There's a lot more to it. For
>> instance, sessions are single threaded by PHP. You probably start a
>> session before the download, and don't close it until the page ends.
>> During this time, you will not be able to access other pages which use
>> sessions (but other people can access their pages because they're using
>> different sessions).
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================- Hide quoted text -
>>
>> - Show quoted text -

>
> I see. That's true.
>
> Here's the structure then.
> Show Doc.
> Include functions file (which has session_start()) at the top in
> addition to connections to mysql.
> Perform mysql query using GET vars and SESSION vars.
> Determine the filename I want to display.
> readfile_chunked the file.
>
> From what you say, unless the page ends, the session will be
> 'locked'. If I pass the session variables via GET instead and close
> the session as the 2nd line of showdoc.php (1st line includes the file
> which starts the session) before I get the filename data and display
> it, will that work?
> TomH.
>


The problem is the session itself is locked as long as it is open. It
doesn't make any difference if you pass variables in the $_GET or not.
Just close the session as soon as you're done with it (i.e. before you
start the file download).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #8 (permalink)  
Old 06-14-2008
tomhawkins1@gmail.com
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

On Jun 14, 2:51*pm, tomhawki...@gmail.com wrote:
> On Jun 14, 1:26*pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>
>
>
>
> > tomhawki...@gmail.com wrote:
> > > On Jun 14, 1:09 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> > >> tomhawki...@gmail.com wrote:
> > >>> On Jun 14, 11:19 am, tomhawki...@gmail.com wrote:
> > >>>> Hi
> > >>>> I currently have a site where users can upload files. These files can
> > >>>> be doc, wmv, jpeg, xls, dwf, dwf and dwg.
> > >>>> These files are uploaded to /home/**user**/uploads and not /home/
> > >>>> **user**/public_html/uploads to prevent any old user from browsing
> > >>>> them.
> > >>>> I then use a general showDoc page with the following function (from
> > >>>> php.net)
> > >>>> function readfile_chunked($filename,$retbytes=true) {
> > >>>> * * * * * * * * $chunksize = 1*(1024*1024); // how many bytes per chunk
> > >>>> * * * * * * * * $buffer = '';
> > >>>> * * * * * * * * $cnt =0;
> > >>>> * * * * * * * * // $handle = fopen($filename, 'rb');
> > >>>> * * * * * * * * $handle = fopen($filename, 'rb');
> > >>>> * * * * * * * * if ($handle === false) {
> > >>>> * * * * * * * * * * * * return false;
> > >>>> * * * * * * * * }
> > >>>> * * * * * * * * while (!feof($handle)) {
> > >>>> * * * * * * * * * * * * $buffer = fread($handle, $chunksize);
> > >>>> * * * * * * * * * * * * echo $buffer;
> > >>>> * * * * * * * * * * * * ob_flush();
> > >>>> * * * * * * * * * * * * flush();
> > >>>> * * * * * * * * * * * * if ($retbytes) {
> > >>>> * * * * * * * * * * * * * * * * $cnt += strlen($buffer);
> > >>>> * * * * * * * * * * * * }
> > >>>> * * * * * * * * }
> > >>>> * * * * * * * * $status = fclose($handle);
> > >>>> * * * * * * * * if ($retbytes && $status) {
> > >>>> * * * * * * * * * * * * return $cnt; // return num. bytes delivered like readfile() does.
> > >>>> * * * * * * * * }
> > >>>> * * * * * * * * return $status;
> > >>>> * * * * }
> > >>>> which is called here
> > >>>> * * * * header("Pragma: public");
> > >>>> * * * * header("Expires: 0");
> > >>>> * * * * header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> > >>>> * * * * header("Cache-Control: private",false);
> > >>>> * * * * header("Content-Type: $ctype");
> > >>>> * * * * header("Content-Disposition: inline; filename=
> > >>>> \"".basename($filename)."\";" );
> > >>>> * * * * header("Content-Transfer-Encoding: binary");
> > >>>> * * * * header("Content-Length: ".filesize($filename));
> > >>>> * * * * readfile_chunked("$filename");
> > >>>> * * * * exit();
> > >>>> Now, if I have a file of more than about 3MB (tried with a wmv and
> > >>>> dxf), it won't show, and my whole site becomes unresponsive to any
> > >>>> input until I close the browser, open IE again and log in again.
> > >>>> filename and ctype must be being passed correctly but the size of the
> > >>>> file seems to make it hang. I have succeded in uploading files of up
> > >>>> to 15MB but the larger ones won't display!
> > >>>> Any ideas?
> > >>>> TomH
> > >>> A quick update. If I right click the link and save target as, the
> > >>> files download perfectly but I want to display, not download them. Two
> > >>> things happen though. No other link on the site will work until the
> > >>> file has finished downloading. Secondly, it I cancel the download
> > >>> before it completes, the same 'hang' happens and I have to close and
> > >>> reopen the browser.
> > >>> TomH.
> > >> Try a different browser.

>
> > >> The "no other link on the site will work" can be normal, depending on
> > >> how your code is structured. *The rest of your problems sound like a
> > >> browser problem.

>
> > >> --
> > >> ==================
> > >> Remove the "x" from my email address
> > >> Jerry Stuckle
> > >> JDS Computer Training Corp.
> > >> jstuck...@attglobal.net
> > >> ==================- Hide quoted text -

>
> > >> - Show quoted text -

>
> > > I'll try something else. When you say 'depends on how your code is
> > > structured', short of a mysql query to get the filename, the code is
> > > above. Is there anything in that?

>
> > > TomH.

>
> > I'm sure that isn't your entire page. *There's a lot more to it. *For
> > instance, sessions are single threaded by PHP. *You probably start a
> > session before the download, and don't close it until the page ends.
> > During this time, you will not be able to access other pages which use
> > sessions (but other people can access their pages because they're using
> > different sessions).

>
> > --
> > ==================
> > Remove the "x" from my email address
> > Jerry Stuckle
> > JDS Computer Training Corp.
> > jstuck...@attglobal.net
> > ==================- Hide quoted text-

>
> > - Show quoted text -

>
> I see. That's true.
>
> Here's the structure then.
> Show Doc.
> Include functions file (which has session_start()) at the top in
> addition to connections to mysql.
> Perform mysql query using GET vars and SESSION vars.
> Determine the filename I want to display.
> readfile_chunked the file.
>
> From what you say, *unless the page ends, the session will be
> 'locked'. If I pass the session variables via GET instead and close
> the session as the 2nd line of showdoc.php (1st line includes the file
> which starts the session) before I get the filename data and display
> it, will that work?
> TomH.- Hide quoted text -
>
> - Show quoted text -


Scratch that. Just don't start the session in the first place.

Works fine now. I just pass the var I was storing in session via GET
and go from there.

Thanks for you help - I never would have thought it was related to
sessions.
TomH
Reply With Quote
  #9 (permalink)  
Old 06-14-2008
ThanderMaX
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

On Jun 14, 3:19*am, tomhawki...@gmail.com wrote:
> Hi
>
> I currently have a site where users can upload files. These files can
> be doc, wmv, jpeg, xls, dwf, dwf and dwg.
>
> These files are uploaded to /home/**user**/uploads and not /home/
> **user**/public_html/uploads to prevent any old user from browsing
> them.
>
> I then use a general showDoc page with the following function (from
> php.net)
>
> function readfile_chunked($filename,$retbytes=true) {
> * * * * * * * * $chunksize = 1*(1024*1024); // how many bytes per chunk
> * * * * * * * * $buffer = '';
> * * * * * * * * $cnt =0;
> * * * * * * * * // $handle = fopen($filename, 'rb');
> * * * * * * * * $handle = fopen($filename, 'rb');
> * * * * * * * * if ($handle === false) {
> * * * * * * * * * * * * return false;
> * * * * * * * * }
> * * * * * * * * while (!feof($handle)) {
> * * * * * * * * * * * * $buffer = fread($handle,$chunksize);
> * * * * * * * * * * * * echo $buffer;
> * * * * * * * * * * * * ob_flush();
> * * * * * * * * * * * * flush();
> * * * * * * * * * * * * if ($retbytes) {
> * * * * * * * * * * * * * * * * $cnt += strlen($buffer);
> * * * * * * * * * * * * }
> * * * * * * * * }
> * * * * * * * * $status = fclose($handle);
> * * * * * * * * if ($retbytes && $status) {
> * * * * * * * * * * * * return $cnt; // return num.. bytes delivered like readfile() does.
> * * * * * * * * }
> * * * * * * * * return $status;
>
> * * * * }
>
> which is called here
>
> * * * * header("Pragma: public");
> * * * * header("Expires: 0");
> * * * * header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> * * * * header("Cache-Control: private",false);
> * * * * header("Content-Type: $ctype");
> * * * * header("Content-Disposition: inline; filename=
> \"".basename($filename)."\";" );
> * * * * header("Content-Transfer-Encoding: binary");
> * * * * header("Content-Length: ".filesize($filename));
> * * * * readfile_chunked("$filename");
> * * * * exit();
>
> Now, if I have a file of more than about 3MB (tried with a wmv and
> dxf), it won't show, and my whole site becomes unresponsive to any
> input until I close the browser, open IE again and log in again.
> filename and ctype must be being passed correctly but the size of the
> file seems to make it hang. I have succeded in uploading files of up
> to 15MB but the larger ones won't display!
>
> Any ideas?
>
> TomH


Try "Content-Disposition: attachment;......"
It will show the open/save dialog box in IE
Reply With Quote
  #10 (permalink)  
Old 06-14-2008
Jerry Stuckle
 
Posts: n/a
Default Re: IE 'hangs' when I try to display an uploaded file

ThanderMaX wrote:
> On Jun 14, 3:19 am, tomhawki...@gmail.com wrote:
>> Hi
>>
>> I currently have a site where users can upload files. These files can
>> be doc, wmv, jpeg, xls, dwf, dwf and dwg.
>>
>> These files are uploaded to /home/**user**/uploads and not /home/
>> **user**/public_html/uploads to prevent any old user from browsing
>> them.
>>
>> I then use a general showDoc page with the following function (from
>> php.net)
>>
>> function readfile_chunked($filename,$retbytes=true) {
>> $chunksize = 1*(1024*1024); // how many bytes per chunk
>> $buffer = '';
>> $cnt =0;
>> // $handle = fopen($filename, 'rb');
>> $handle = fopen($filename, 'rb');
>> if ($handle === false) {
>> return false;
>> }
>> while (!feof($handle)) {
>> $buffer = fread($handle, $chunksize);
>> echo $buffer;
>> ob_flush();
>> flush();
>> if ($retbytes) {
>> $cnt += strlen($buffer);
>> }
>> }
>> $status = fclose($handle);
>> if ($retbytes && $status) {
>> return $cnt; // return num. bytes delivered like readfile() does.
>> }
>> return $status;
>>
>> }
>>
>> which is called here
>>
>> header("Pragma: public");
>> header("Expires: 0");
>> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
>> header("Cache-Control: private",false);
>> header("Content-Type: $ctype");
>> header("Content-Disposition: inline; filename=
>> \"".basename($filename)."\";" );
>> header("Content-Transfer-Encoding: binary");
>> header("Content-Length: ".filesize($filename));
>> readfile_chunked("$filename");
>> exit();
>>
>> Now, if I have a file of more than about 3MB (tried with a wmv and
>> dxf), it won't show, and my whole site becomes unresponsive to any
>> input until I close the browser, open IE again and log in again.
>> filename and ctype must be being passed correctly but the size of the
>> file seems to make it hang. I have succeded in uploading files of up
>> to 15MB but the larger ones won't display!
>>
>> Any ideas?
>>
>> TomH

>
> Try "Content-Disposition: attachment;......"
> It will show the open/save dialog box in IE
>


That depends on how the user has the browser (any browser) configured.

You can recommend something (which is what your content-disposition
does), but you can't force something on the user.

Also, your recommendation would do exactly the opposite of what he wants.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:44 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0