Forum Moderators: coopster
[webmasterworld.com...]
But I am lost all I get are header errors... I am not sure if it is the old php that we run with or most likely me...
I was hoping someone would help me out
my download php :
<?php
function download($file)
{
$filename = $file;
print($filename .' is the file name \n' );
$filename = realpath($filename); //server specific
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if (! file_exists( $filename ) )
{
die("NO FILE HERE");
};
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 "jpe": 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");
header("Content-Disposition: attachment; filename=".basename($filename).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
@readfile("$filename") or die("File not found.");
exit();
}
?>
my test.php as I call it is:
<?php
include('download.php'); // this is your script which I've turned into a function.
?>
<?php
if (isset($_POST['download'])) {
$filename =('leaveform.pdf');//$_POST['leaveform.pdf'];
download($filename);
}
?>
<body>
<form method="post" action="<?php echo $_SERVER['download.php'];?>">
<input type="submit" name="download" value="Click to Download the PDF"/>
<input type="hidden" name="file" value="leaveform.pdf" />
</form>
<? print($filename . " is the file name.")?>
</body>
can any tell me where I am going wrong?
errors:
leaveform.pdf is the file name \n
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/Test1.php:7) in /var/www/html/download.php on line 29
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/Test1.php:7) in /var/www/html/download.php on line 30
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/Test1.php:7) in /var/www/html/download.php on line 31
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/Test1.php:7) in /var/www/html/download.php on line 32
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/Test1.php:7) in /var/www/html/download.php on line 33
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/Test1.php:7) in /var/www/html/download.php on line 34
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/Test1.php:7) in /var/www/html/download.php on line 35
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/Test1.php:7) in /var/www/html/download.php on line 36
%PDF-1.4 %âãÏÓ 8 0 obj << /Linearized 1 /O 11 /H [ 4985 640 ] /L 68697 /E 65904 /N 1 /T 68420 >> endobj xref 8 198 0000000016 00000 n 0000004306 00000 n 0000004413 00000 n 0000005625 00000 n 0000005963 00000 n 0000006403 00000 n 0000006687 00000 n 0000007113 00000 n 0000007531 00000 n 0000007643 00000 n 0000008992 00000 n 0000009217 00000 n 0000009441 00000 n 0000009667 00000 n 0000009891 00000 n 0000010116 00000
The Binary garbage is, I beleive, the file.
<?php
include('download.php'); // this is your script which I've turned into a function.
?>
RIGHT HERE
<?php
if (isset($_POST['download'])) {
$filename =('leaveform.pdf');//$_POST['leaveform.pdf'];
download($filename);
}
?>
Try this instead:
<?php
include('download.php');
if (isset($_POST['download'])) {
$filename =('leaveform.pdf');//$_POST['leaveform.pdf'];
download($filename);
}
?>
The out put in its entierty is to large to post. These are the last few lines.
0000000016 00000 n 0000004306 00000 n 0000004413 00000 n 0000005625 00000 n 0000005963 00000 n 0000006403 00000 n 0000080689 00000 n 0000080711 00000 n 0000081102 00000 n 0000081124 00000 n 0000081522 00000 n 0000081544 00000 n 0000081937 00000 n 0000081959 00000 n 0000082362 00000 n 0000082384 00000 n 0000082775 00000 n 0000082797 00000 n 0000083196 00000 n 0000083218 00000 n 0000083609 00000 n 0000083631 00000 n 0000084029 00000 n 0000084051 00000 n trailer << /Size 264 /Info 7 0 R /Root 9 0 R /Prev 173 /ID[] >> startxref 86015 %%EOF
also the code for the Test1.php is :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
include('download.php');
if (isset($_POST['download']))
{
$filename =('leaveform.pdf');//$_POST['leaveform.pdf'];
download($filename);
}
?>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="submit" name="download" value="Click to Download the PDF"/>
<input type="hidden" name="file" value="leaveform.pdf" />
</form>
</body>
</html>
<?php
if (isset($_POST['download']))
{
include('download.php');
$filename =('leaveform.pdf');//$_POST['leaveform.pdf'];
download($filename);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
include('download.php');
if (isset($_POST['download']))
{
$filename =('leaveform.pdf');//$_POST['leaveform.pdf'];
download($filename);
}
?>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="submit" name="download" value="Click to Download the PDF"/>
<input type="hidden" name="file" value="leaveform.pdf" />
</form>
</body>
</html>
Warning: Cannot add header information - headers already sent by (output started at /var/www/html/download.php:37) in /var/www/html/download.php on line 28
I am not sure how to fix this and I am getting very frustrated. I am thinking that what I want to do is impossible.
THanks
- headers() cannot be sent if output has already been made
(remembering that 'output' can be
echo()statements, embedded HTML or even "white space" outside of the
<php? ...?>statements)
If so, then what you need to investigate is:
ob_start())