Hi there,
I have been working on a web site and at a certain stage, I got the following errors while trying to upload images:
Warning: Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/projectAD/includes/header.html:8) in /Library/WebServer/Documents/projectAD/loggedin.php on line 84
now here is loggedin.php file:
<?php # loggedin.php #2
// The designer is redirected here from login.php.
session_start(); // Start the session.
// If no session value is present, redirect the user:
if (!isset($_SESSION[‘user_id’])) {
require_once (‘loginFunctions.inc.php’);
$url = absolute_url();
header("location: ".$url);
exit();
}
$page_title = ‘Welcome to ADesigns: Logged In!’;
include (‘includes/header.html’);
// Print a customized message:
echo “<h1>Logged In!</h1> <p>You are now logged in, {$_SESSION[‘firstname’]}!</p>”;
// Now we upload, view and delete photos here:
require_once (‘mysql_connect.php’);
if ( isset($_GET[‘action’]) )
{
$action = $_GET[‘action’];
}
else
{
$action = “”;
}
if ( ($action == 'view' or $action == 'dnld') and isset($_GET['id']) )
{
$id = $_GET['id'];
// User is retreving a file
$sql = "SELECT filename, mimetype, filedata FROM images WHERE id = '$id' ";
$result = @mysql_query($sql);
if (!$result)
{
exit('Database error: ' . mysql_error());
}
$file = mysql_fetch_array($result);
if(!$file)
{
exit('File with given ID not found in database!');
}
$filename = $file['filename'];
$mimetype = $file['mimetype'];
$filedata = $file['filedata'];
$disposition = 'inline';
if ($action == 'dnld')
{
$disposition = 'attachment';
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5') or strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 7') )
{
$mimetype = 'application/x-download';
}
}
header("content-disposition: $disposition; filename=$filename");
header("content-type: $mimetype");
header('content-lenght: ' . strlen($filedata));
echo ($filedata);
exit();
}
else if($action == 'del' and isset($_GET['id']))
{
$id = $_GET['id'];
// User deleting a file
$sql = "DELETE FROM images WHERE id = '$id'";
$ok = @mysql_query($sql);
if (!$ok)
{
exit('Database error: ' . mysql_error());
}
header('location: ' . $_SERVER['PHP_SELF']);
exit();
}
else if (isset($_FILES['upload']) )
{
// Bail out if the file isn't really an upload.
if (!is_uploaded_file($_FILES['upload']['tmp_name']))
{
exit('There was no file uploaded!');
}
$uploadfile = $_FILES['upload']['tmp_name'];
$uploadname = $_FILES['upload']['name'];
$uploadtype = $_FILES['upload']['type'];
$uploaddesc = $_POST['desc'];
// Open file or binary reading ('rb')
$tempfile = fopen($uploadfile, 'rb');
// Read the entire file into memory using PHP's
// filesize fucntion to get the size.
$filedata = fread($tempfile, filesize($uploadfile));
// Prepare for database insert by adding backslashes
// before special characters.
$filedata = addslashes($filedata);
// Create the SQL query.
$sql = "INSERT INTO images SET
filename = '$uploadname',
mimetype = '$uploadtype',
description = '$uploaddesc',
filedata = '$filedata'";
// Perform the insert.
$ok = @mysql_query($sql);
if(!$ok)
{
exit('Database error storing file: ' . mysql_error());
}
header('location: ' . $_SERVER['PHP_SELF']);
exit();
}
// Default page view: lists stored files
$sql = 'SELECT id, filename, mimetype, description FROM images';
$filelist = @mysql_query($sql);
if (!$filelist)
{
exit('Database error: ' . mysql_error());
}
?>
<h1>Upload your images:</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<p><label>Upload File:<br />
<input type="file" name="upload" /></label></p>
<p><label>File Description:<br />
<input type="text" name="desc" maxlength="255" /></label></p>
<p><input type="submit" value="Upload" /></p>
</form>
<p>The following are stored in the database:</p>
<table>
<tr>
<th colspan="2">Filename</th>
<th>Type</th>
<th>Description</th>
</tr>
<?php
if (mysql_num_rows($filelist) > 0)
{
while ($f = mysql_fetch_array($filelist))
{
?>
<tr valign="top">
<td>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=view&id=<?php echo $f['id']; ?>">
<?php echo $f['filename']; ?></a>
</td>
<td><?php echo $f['mimetype']; ?></td>
<td><?php echo $f['description']; ?></td>
<td>
[<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=dnld&id=<?php echo $f['id']; ?>">Download</a> |
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=del&id=<?php echo $f['id']; ?>" onclick="return confirm('Delete this file?');">Delete</a>]
</td>
</tr>
<?php
}
}
else
{
?>
<tr><td colspan=“3”>No Files!</td></tr>
<?php
}
?>
</table>
<?php
echo “<p><a href=\“logout.php\”>Logout</a></p>”;
include (‘includes/footer.html’);
?>
I noted that line and tried to rectify the problem by looking at the header.html file which is called from the includes file. I understand from what I have read from read is that it could be that I have white spaces in my php.ini file.
Could this be true and if so how do I get rid of white spaces from php.ini. By the way, here is the header.html file which was called by the include function:
<!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=utf-8” />
<title><?php echo $page_title;?></title>
<link href=“css/main.css” rel=“stylesheet” type=“text/css” />
</head>
<body>
<table id=“outerTable”>
<tr><td id=“logo”>
<div>
<img src=“” width=“” height=“” alt=“company_logo” />
</div>
</td></tr>
<tr><td id =“mainMenu”>
<div>
<a href=“home.html”>Home</a> |
<a href=“specials.html”>Specials</a> |
<a href=“designers.html”>Participate</a> |
<a href=“aboutAd.html”>About ADesigns</a> |
<a href=“contact.php”>Contact Us</a>
</div>
</td></tr>
<tr><td id=“banner”> <! – page banner image –>
<img src=“” width=“” height=“” alt=“welcome to ADesigns”>
</td></tr>
<tr><td>
<table id=“contentTable”><tr>
<td id=“contentLeft”>
<div id=“leftSideBar”>
<h3> CATEGORIES</h3>
<ul>
<li><a href="#">Jeans</a></li>
<li><a href="#">Pants</a></li>
<li><a href="#">Capris & Shorts</a></li>
<li><a href="#">Skirts</a></li>
<li><a href="#">Dresses</a></li>
<li><a href="#">Sweaters</a></li>
<li><a href="#">Tops</a></li>
<li><a href="#">Ts & Camis</a></li>
</ul>
<h3>DESIGNERS</h3>
<ul>
<li><a href="#">Fred Perry</a></li>
<li><a href="#">Full CIrcle</a></li>
<li><a href="#">Hannah Smith</a></li>
<li><a href="#">Jacob & Co.</a></li>
<li><a href="#">Lee</a></li>
<li><a href="#">Oasis</a></li>
<li><a href="#">Polo</a></li>
<li><a href="#">Boss</a></li>
</ul>
</div> <! -- leftSideBar -->
</td>
<td id="contentCenter">
<div id="mainContent">
Please help,
Thank you