I'm just learning PHP, and I'm having a problem using fpassthru(). I
want to download a file using the following code segment I found,
which I put into my testing file called portal.php:
$fileString = './' . $params[1];
// translate file name properly for Internet Explorer.
if ( strstr( $_SERVER['HTTP_USER_AGENT'], "MSIE" )) {
$params[1] = preg_replace( '/\./', '%2e', $params[1],
substr_count($params[1], '.') - 1 );
}
header( "Cache-Control: " ); // leave blank for IE
header( "Pragma: " ); // leave blank for IE
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=\"" .
$params[1] . "\"" );
header( "Content-length:" . (string)(filesize( $fileString )));
sleep(1);
$fdl = @fopen( $fileString, 'rb' );
fpassthru( $fdl );
However, when I run it, I get the following:
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 178
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 179
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 180
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 182
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 183
The contents of the file I am trying to download (an html file) is
then displayed, interpreted as if it were appended to the end of
portal.php. Does anyone know what is causing this, and how I can fix
it? Thanks in advance to all who respond. 4 2605
> Warning: Cannot modify header information - headers already sent by (output started at /export/home/.../portal.php:26) in /export/home/.../portal.php on line 178
Warning: Cannot modify header information - headers already sent by (output started at /export/home/.../portal.php:26) in /export/home/.../portal.php on line 179
Warning: Cannot modify header information - headers already sent by (output started at /export/home/.../portal.php:26) in /export/home/.../portal.php on line 180
Warning: Cannot modify header information - headers already sent by (output started at /export/home/.../portal.php:26) in /export/home/.../portal.php on line 182
Warning: Cannot modify header information - headers already sent by (output started at /export/home/.../portal.php:26) in /export/home/.../portal.php on line 183
these are ussually caused when you have already output data to the browser,
if any output has been sent (even a single space) then headers can not be
sent
"Filth" <pe***@petermcdonald.co.uk> wrote in message news:<yn*******************@news-text.cableinet.net>... these are usually caused when you have already output data to the browser, if any output has been sent (even a single space) then headers can not be sent
Thanks for your response. Now, am I using the wrong technique to download
a file from a host server? Is there a better way, or am I just using the
correct technique incorrectly? I would appreciate some guidance, since
PHP in general is still new to me.
Leslie Houk wrote: Does anyone know what is causing this, and how I can fix it? Thanks in advance to all who respond.
You need to use output buffering. Check the manual at http://www.php.net/ob_start for somewhere to start.
Regards,
Andy
Andy Barfield <ab**********@yahoo.com> wrote in message news:<k6********************@nildram.net>... Leslie Houk wrote: Does anyone know what is causing this, and how I can fix it? Thanks in advance to all who respond.
You need to use output buffering. Check the manual at http://www.php.net/ob_start for somewhere to start.
Regards,
Andy
Andy,
Thanks for the link! The last user comment on that page pointed
me to "http://www.devshed.com/c/a/PHP/Output-Buffering-With-PHP/",
which told me exactly how to do what I need.
Leslie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: rain |
last post by:
Hello,
I am having some serious problems executing a command on my redhat linux
machine using exec, shell_exec, or any variants thereof.
I have a string saved into a variable like:
$mystring...
|
by: Bert |
last post by:
Hello,
I'm using a script to handle downloads of files, it seems to work but
I'm getting random server errors. I guess it has something to do with
the filesize. The script will be needed to...
|
by: Uncle_Alias |
last post by:
I would like use some of the GD image functions, so I ran a couple of
short scripts to see if it worked, such as:
<?php
/* Create a red square */
$image = imagecreate(200, 200);
$colorRed =...
|
by: Michael J. Astrauskas |
last post by:
I have a script, which I've called test-loadpic.php and some pages
reference it by means of
<img src="test-loadpic.php?sourcepic=$picNum">
where $picNum stores a number. This part itself works...
|
by: Gooseman |
last post by:
Hi,
I have a page where form data is passed to a php page (just script) to
process the input. This page calls a function to output a file:
function sendFileViaHeader($path, $name) {
$fp =...
|
by: Bill |
last post by:
For my personal use I am accessing a railway timetable page, parsing its
contents and then sending brief relevant information as the subject line of
an email to be read on a mobile phone.
The...
|
by: Yannick Bétemps |
last post by:
Hi all,
As says the topic, I recently encountered problems with customers using
one of my file management applications and being protected in the same
time with Norton Internet Security firewall....
|
by: kevinm3574 |
last post by:
Got the following to pop a download dialogue:
$p = explode('.', $file);
$pc = count($p);
//send headers
if(($pc > 1) AND isset($mimetype]))
{
//display file inside browser...
|
by: gezerpunta |
last post by:
Hi
I need to fetch lobs with php script. I found it but there is an
error.
$stmt = $db->prepare("select * from test where oid = 17056");
$stmt->execute();
$stmt->bindColumn('oid', $lob,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |