Welcome! Log In Create A New Profile Forum Rules

Advanced

Everything except image - Scripts 14.7 / 14.8 - solved

Posted by DeprecatedDiva 
Everything except image - Scripts 14.7 / 14.8 - solved
four years ago
I need some help getting the image to show. I've been struggling with this issue for three days now. Hopefully I've included enough info (system info is in my sig):

Although I am using PHP 5 to take advantage of using mysqli for testing purposes, I am writing the the lower mysql functions as my host will not upgrade the site to PHP 5 because it is "untested".

Now, I am getting ALL of the text and my SOURCE code is showing the following:

<td style="text-align:left;color:#000000;background-color:#ffffcc;" colspan="3">
<!-- Content starts here! --><div style="text-align:center;" ><br />
		<b style="font-size:110%;">Chinese Temple</b><br />by 
		Chon Dou
		<br />16 x 12
		<br />$375.00
		<a href="add_cart.php?pid=1">Add to Cart</a>

		</div>
<br /><div style="text-align:center;">
<img src="show_image.php?image=bignchs.jpg" width="1080" height="632" alt="Chinese Temple" />
<br />Chinese Temple
</div><!-- Script 14.4 - footer.html -->
<!-- Content starts here! -->
		<br /></td>

but for some reason, I am not getting an image.


The image was successfully uploaded via the add_print.php file and is located in the uploads folder located outside the web.

The browse_prints.php shows that the print is available to be viewed.

But when all is said and done.... No image.

I've already compared my script and your script and except for styling methods and the fact that my files are two-deep, our scripts appear to match. Edited to add: I even directly replaced my script with the script from the script_named.zip file. Same exact results.

Here are my view_print.php and my show_image.php files:

view_print.php:
<?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 style=\"text-align:center;\" ><br />
		<b style=\"font-size:110%;\">{$row['print_name']}</b><br />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 style=\"text-align:center;\"><img src=\"show_image.php?image={$row['image_name']}\" $image[3] alt=\"{$row['print_name']}\" />";
		} else {
			echo "<div style=\"text-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 style=\"text-align:center;\">This page has been accessed in error!</div>';
}

// Complete the page.
include ('./includes/footer.html');
?>

show_image.php
<?php # Script 14.8 - show_image.php
// This page 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);

?>

TIA to all.

Deprecated Diva

My PHP resources:
"PHP and MySQL: Visual QuickPro Guide (2nd Ed.)" - WindowsXP SP2/Apache 1.3.33/PHP 5.1.1/MySQL 4.1.9



Edited 5 time(s). Last edit was four years ago by DeprecatedDiva.
Re: Everything except image - Scripts 14.7 / 14.8
four years ago
I am still having trouble wrapping my head around the fact that in addition to folder permissions, it is important to make sure that apache also recognizes the folder outside the web as a valid alias for the script to be able to act on it. I've added an 'uploads' alias which solved my problem.

Edited to add:
This fixed my view problems for the Chapter 11 images.php(11.2) files outside the web. I still cannot see the images for the scripts listed in the title.

Deprecated Diva

My PHP resources:
"PHP and MySQL: Visual QuickPro Guide (2nd Ed.)" - WindowsXP SP2/Apache 1.3.33/PHP 5.1.1/MySQL 4.1.9



Edited 2 time(s). Last edit was four years ago by DeprecatedDiva.
Found the error. There was a missing ")" in the content-disposition header....
DeprecatedDiva Wrote:
-------------------------------------------------------
> Found the error. There was a missing ")" in the
> content-disposition header....

I am having problems with the same scripts, so where exactly was the missing ")"

I thought that the problem may be with "show_image.php" and the settings in the php.ini file for allowing the image to load.

I am not sure if it is possible to use ini_set() to override this but I am trying to find out.

The Host that I am using is on a WindowsXP set up as well.

I am not having trouble running the scripts On my OSX test server.

Actually Just found a reference in another post regarding displaying an uploaded picture.
[www.dmcinsights.com]
Probably something to do with mime_content_type(), will check the book at home later.



Edited 2 time(s). Last edit was four years ago by markboyd.
Re: Everything except image - Scripts 14.7 / 14.8 - php.ini
four years ago
It looks as if I should have read pp614-615 first regarding the settings for the php.ini file.

I will try and get my host to change the settings for php_mime_magic.dll.

If I can't get that done will try and see if there is a ini_set() workaround.
Sorry, only registered users may post in this forum.

Click here to login