Jump to content

Displaying multiple images from a mysql database


walterio

Recommended Posts

I am trying to display 2 images on a page showing the inside and outside of an RV for sale.  I uploaded the two images to separate directories naming them the same integer (auto_increment field from a mysql database) I have adapted a script that is working on another page (www.burdettecamping.com/Pre-Owned_Units.php) displaying one different image.  All three are uploaded at the same time.  If I view the source of the page, for example (http://www.burdettecamping.com/view_unit.php?pid=65) the image sizes and names are correct but no images are displayed.

 

This is the script that is correctly displaying the first image:

<?php #  show_image.php
// This pages retrieves and shows an image.

// Flag variables:
$image = FALSE;
$name = (!empty($_GET['name'])) ? $_GET['name'] : 'print image';

// Check for an image value in the URL:
if (isset($_GET['image']) && is_numeric($_GET['image']) ) {

// Full image path:
$image = '../uploads/' . (int) $_GET['image'];

// Check that the image exists and is a file:
if (!file_exists ($image) || (!is_file($image))) {
	$image = FALSE;
}

}

// If there was a problem, use the default image:
if (!$image) {
$image = 'images/kerrysleep.JPG';
$name = 'unavailable.png';
}

// Get the image information:
$info = getimagesize($image);
$fs = filesize($image);

// Send the content information:
header ("Content-Type: {$info['mime']}\n");
header ("Content-Disposition: inline; filename=\"$name\"\n");
header ("Content-Length: $fs\n");

// Send the file:
readfile ($image);

?>

 

Here is one of the modified ones that gives the correct file name and size to the browser but no image is displayed.

<?php #  show_imageoutside.php
// This pages retrieves and shows an image.

// Flag variables:
$oimage = FALSE;
$oname = (!empty($_GET['name'])) ? $_GET['name'] : 'print image';

// Check for an image value in the URL:
if (isset($_GET['oimage']) && is_numeric($_GET['oimage']) ) {

// Full image path:
$oimage = '../uploads/outside/' . (int) $_GET['oimage'];

// Check that the image exists and is a file:
if (!file_exists ($oimage) || (!is_file($oimage))) {
	$oimage = FALSE;
}

}

// If there was a problem, use the default image:
if (!$oimage) {
$oimage = 'images/unavailable.png';
$oname = 'unavailable.png';
}

// Get the image information:
$oinfo = getimagesize($oimage);
$ofs = filesize($oimage);

// Send the content information:
header ("Content-Type: {$oinfo['mime']}\n");
header ("Content-Disposition: inline; filename=\"$oname\"\n");
header ("Content-Length: $ofs\n");

// Send the file:
readfile ($oimage);

?>

 

The page that is trying to display the two images is found by clicking on one of the images in the page linked to above and below is the code for that page.

<?php # viewUnit.php
// This page displays the details for a particular unit.

$row = FALSE; // Assume nothing!

if (isset($_GET['pid']) && is_numeric($_GET['pid']) ) { // Make sure there's a unit ID!

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

// Get the unit info:
require_once ('../mysqli_connectp.php'); 
$q = "SELECT unit_id , price , description , yrmakemdl , oimage_name , iimage_name FROM units WHERE unit_id = $pid";

$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) == 1) { // Good to go!

	// Fetch the information:
	$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);

	// Start the HTML page:
include('include2unittop.html');

	// Get the image information and display the image:
	if ($image = @getimagesize ("../uploads/outside/$pid")) {
		echo "<div class=\"uphoto\"><img src=\"show_imageoutside.php?image=$pid&name=" . urlencode($row['oimage_name']) . "\" $image[3] alt=\"{$row['yrmakemdl']}\" /></div>\n";
	} else {
	echo "<div align=\"center\">No image available.</div>\n";
	}

	// Get the image information and display the image:
	if ($image = @getimagesize ("../uploads/inside/$pid")) {
		echo "<div class=\"uphoto\"><img src=\"show_imageinside.php?image=$pid&name=" . urlencode($row['iimage_name']) . "\" $image[3] alt=\"{$row['yrmakemdl']}\" /></div>\n";
	} else {
	echo "<div align=\"center\">No image available.</div>\n";
	}

echo"<p class=\"UnitDescription\">{$row['yrmakemdl']}</p>";
echo"<p class=\"UnitDescription\">{$row['description']}</p>";
echo"<p class=\"UnitDescriptionStrong\">Now Only {$row['price']}</p>";
echo"</div>";


} // End of the mysqli_num_rows() IF.

mysqli_close($dbc);

}

if (!$row) { // Show an error message.
include('include2unittop.html');
echo '</div>';
echo '			<div id="homecontentmiddle">';
echo '				<h1>Error 404; File Not Found<br></br>The page you are looking for has most likely been upgraded, <br></br>please use the above navigation to find what you need,<br></br>Thanks.</h1>';
echo '				<p class="home"></p>';
echo '			</div><!-- end homecontentmiddle-->';

}

// Complete the page:
include('includefooter.html');
?>

 

This is my first time posting on this forum and I am a beginner to PHP.

 

I'm trying to find out why the images are not being displayed even though the image name and image size info are being passed to the browser via the "showimage" script.

 

Any suggestions are appreciated

 

I am using the following setup:

Mac OS X 10.5.6

Coda 1.6.4 from Panic Software for my editing

php version is 5.2.1 (Hosted at powweb.com)

MySQL version is 5.0.45 (Hosted at powweb.com)

phpMyAdmin - 2.8.0.1 (Hosted a powweb.com)

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.