Jump to content

a view script and a show image script that is called by view script


sailbaby

Recommended Posts

Hi All:

 

I have been doing a tutorial and have pretty much breezed through it even debugging queries and all, however, these two scripts aren't working with each other.  Either the view_print.php script isn't calling up the show_image.php script or there is something wrong in the show_image.php script.  I have not written these scripts and have tried to get online help from the writer of the book's forum, but they are going around in circles with me not even addressing the quesiton I am asking.  If anybody could kindly look at these scripts and tell me if there's something wrong, I would appreciate it.  Below are the two cut and pasted scripts...

 

<?php # Script 14.7 - view_print.php

// This page displays the details for a particular print.

 

$problem = FALSE; // Assume no problem.

 

if (isset($_GET['pid'])) { // Make sure there's a print ID.

 

$pid = (int) $_GET['pid'];

 

require_once ('../mysql_connect.php'); // Connect to the database.

 

$query = "SELECT CONCAT_WS(' ', first_name, middle_name, last_name) AS name, print_name, price, description, size, image_name FROM artists, prints WHERE artists.artist_id = prints.artist_id AND prints.print_id = $pid";

$result = mysql_query ($query);

 

if (mysql_num_rows($result) == 1) { // Good to go!

 

// Fetch the information.

$row = mysql_fetch_array ($result, MYSQL_ASSOC);

 

// Start the HTML page.

$page_title = $row['print_name'];

include ('./includes/header.html');

 

// Display a header.

echo "<div align=\"center\">

<b>{$row['print_name']}</b> by

{$row['name']}

<br />{$row['size']}

<br />\${$row['price']}

<a href=\"add_cart.php?pid=$pid\">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['print_name']}\" />"; } else {

echo "<div align=\"center\">No image available.";

}

echo "<br />{$row['description']}</div>";

 

} else { // No record returned from the database.

$problem = TRUE;

}

 

mysql_close(); // Close the database connection.

 

} else { // No print ID.

$problem = TRUE;

}

 

if ($problem) { // Show an error message.

$page_title = 'Error';

include ('./includes/header.html');

echo '<div align="center">This page has been accessed in error!</div>';

}

 

// Complete the page.

include ('./includes/footer.html');

?>

 

**********************************************************************

 

<?php # Script 14.8 - show_image.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.gif';

$name = 'unavailable.gif';

}

 

} else { // No image name.

$image = './images/unavailable.gif';

$name = 'unavailable.gif';

}

 

// 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);

 

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.