Hi,
I'm trying to create a script that is able to display information about a selected product from my database. This script also uses another script to display an image for this product.
I'm getting for errors which i don't understand. These are:
Warning: mime_content_type() [function.mime-content-type]: File or path not found './images/unavailable.jpg' in C:\xampplite\htdocs\website\show_image.php on line 24
Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\website\show_image.php:24) in C:\xampplite\htdocs\website\show_image.php on line 28
Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\website\show_image.php:24) in C:\xampplite\htdocs\website\show_image.php on line 29
Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\website\show_image.php:24) in C:\xampplite\htdocs\website\show_image.php on line 30
Here is the code for the first script.
<?php
// This page displays the details for a particular book.
$problem = FALSE; // Assume no problem.
if (isset($_GET['isbn'])) { // Make sure there's a book ISBN.
$isbn = (int) $_GET['isbn'];
require_once ('/mysqli_connect.php'); // Connect to the database.
$query = "SELECT CONCAT_WS(' ', first_name, last_name) AS author, title, price, category, image_name FROM author, books WHERE author.author_id = books.author_id AND books.isbn =$isbn ORDER BY books.title";
$result = mysqli_query ($dbc, $query) or die("Error: ".mysqli_error($dbc));
if (mysqli_num_rows($result) == 1) { // Good to go!
// Fetch the information.
$row = mysqli_fetch_array ($result, MYSQLI_ASSOC);
// Start the HTML page.
$page_title = $row['title'];
include ('./includes/header.php');
// Display a header.
echo "<div align=\"center\">
<b>{$row['title']}</b> by
{$row['author']}
<br />{$row['price']}
<br />{$row['category']}
<br /><a href=\"add_cart.php?isbn=$isbn\">Add to Cart</a>
</div><br />";
// Get the image information and display the image.
if ($image = @getimagesize ("./uploads/{$row['image_name']}")) {
echo "<div align=\"center\"><img src=\"show_image.php?image={$row['image_name']}\" $image[3] alt=\"{$row['title']}\" />";
} else {
echo "<div align=\"center\">No image available.";
}
} else { // No record returned from the database.
$problem = TRUE;
}
mysqli_close($dbc); // Close the database connection.
} else { // No book ID.
$problem = TRUE;
}
if ($problem) { // Show an error message.
$page_title = 'Error';
include ('./includes/header.php');
echo '<div align="center">This page has been accessed in error!</div>';
}
// Complete the page.
include ('./includes/footer.php');
?>
And this is the code for the show image script.
<?php
// This pages retrieves and shows an image.
// Check for an image name.
if (isset($_GET['image'])) {
// Full image path:
$image = "./uploads/{$_GET['image']}";
// Check that the image exists and is a file.
if (file_exists ($image) && (is_file($image))) {
$name = $_GET['image'];
} else {
$image = './images/unavailable.jpg';
$name = 'unavailable.jpg';
}
} else { // No image name.
$image = './images/unavailable.jpg';
$name = 'unavailable.jpg';
}
// Get the image information.
$ft = mime_content_type($image);
$fs = filesize($image);
// Send the file.
header ("Content-Type: $ft\n");
header ("Content-disposition: inline; filename=\"$name\"\n");
header ("Content-Length: $fs\n");
readfile ($image);
?>
Any help would be grealty appreciated. Thanks in advance.