By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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.
Jun 27 '08 #2

P: n/a
to*********@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.
js*******@attglobal.net
==================

Jun 27 '08 #3

P: n/a
On Jun 14, 1:09*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
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.
Jun 27 '08 #4

P: n/a
to*********@gmail.com wrote:
On Jun 14, 1:09 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>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.
js*******@attglobal.net
==================

Jun 27 '08 #5

P: n/a
On Jun 14, 1:26*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
tomhawki...@gmail.com wrote:
On Jun 14, 1:09 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
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.
Jun 27 '08 #6

P: n/a
to*********@gmail.com wrote:
On Jun 14, 1:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>tomhawki...@gmail.com wrote:
>>On Jun 14, 1:09 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
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.
js*******@attglobal.net
==================

Jun 27 '08 #7

P: n/a
On Jun 14, 2:51*pm, tomhawki...@gmail.com wrote:
On Jun 14, 1:26*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:


tomhawki...@gmail.com wrote:
On Jun 14, 1:09 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>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
Jun 27 '08 #8

P: n/a
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
Jun 27 '08 #9

P: n/a
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.
js*******@attglobal.net
==================

Jun 27 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.