473,804 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem using fpassthru()

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_AGEN T'], "MSIE" )) {
$params[1] = preg_replace( '/\./', '%2e', $params[1],
substr_count($p arams[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)(filesi ze( $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.
Jul 17 '05 #1
4 2634
> 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
Jul 17 '05 #2
"Filth" <pe***@petermcd onald.co.uk> wrote in message news:<yn******* ************@ne ws-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.
Jul 17 '05 #3
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
Jul 17 '05 #4
Andy Barfield <ab**********@y ahoo.com> wrote in message news:<k6******* *************@n ildram.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
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2682
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 = "/usr/local/bin/lmc -e add /music/whatever.mp3"; Then I try to execute w/ something like:
1
2435
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 download files of 6 to 8 MB but I've only tested with files from 0.5 to 2.5 MB. I get the following error: The server closed the connection while reading the response. Contact your system administrator. (SERVER_RESPONSE_CLOSE)
15
19108
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 = imagecolorallocate($image, 255, 0, 0); imagefill($image, 0, 0, $colorRed);
7
2376
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 fine. test-loadpic.php uses the "sourcepic" GET variable to reference a file on disk, get it's file/MIME type, transmit the headers and then the raw image. The important code is below:
1
1762
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 = fopen($path . $name, 'r'); header("Cache-Control: ");// leave blank to avoid IE errors header("Pragma: ");// leave blank to avoid IE errors header("Content-type: application/octet-stream");
12
3322
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 problem comes when I try to parse a second page, the url of which, I have derived from an initial page. I cannot go directly to the second (target) page but from the initial page derive the url and put it in a string called $strTarget In one...
0
1319
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. When the Security is not activated, downloading files works fine, but as soon as it is activated they can not download anything bigger than 500kb ! I checked in the source code, and whatever the method to read the file on the server (readfile,...
2
1112
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 header("Content-type: " . $mimetype] . "\n");
1
2667
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, PDO::PARAM_LOB); $stmt->fetch(PDO::FETCH_BOUND); echo $lob;
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.