Jump to content

what do these image names have in common - they aren't displaying!


kate_rose

Recommended Posts

I am in the final stages of double checking the image display code I have been working on that many on this board have helped me with (thank you thank you).  I have a mysql db with image names in it.  I use php to retrieve those names and then a simple bit of code to display them.  Almost all the images are being displayed just fine but a few won't show up.  I have echoed the path for each of these & it looks no different to me than the entries in the database.  I have copied the path directly from the original file.  So I am actually selecting the name - in the my computer view & copying them and inserting them into the db.  I am pretty much stumped.  For example:

 

this file will not display - plant_web_images/Asclepiadaceae/Cryptostegia_grandiflora_leaf_flower.jpg (copied directly from the echo command)

path in 'my computer' view - plant_web_images\Asclepiadaceae\Cryptostegia_grandiflora_leaf_flower

path in mysql db - Asclepiadaceae/Cryptostegia_grandiflora_leaf_flower

(the beginning 'plant_web_images' & '.jpg' are added by a php concat command in the script)

 

this file displays just fine - plant_web_images/Bignoniaceae/Macfadyena_unguis-cati_leaf.jpg (copied from echo)

path in 'my computer' view - plant_web_images\Bignoniaceae\Macfadyena_unguis-cati_leaf

path in mysql db -

 

 

Link to comment
Share on other sites

I am in the final stages of double checking the image display code I have been working on that many on this board have helped me with (thank you thank you).  I have a mysql db with image names in it.  I use php to retrieve those names and then a simple bit of code to display them.  Almost all the images are being displayed just fine but a few won't show up.  I have echoed the path for each of these & it looks no different to me than the entries in the database.  I have copied the path directly from the original file.  So I am actually selecting the name - in the my computer view & copying them and inserting them into the db.  I am pretty much stumped.  For example:

 

this file will not display - plant_web_images/Asclepiadaceae/Cryptostegia_grandiflora_leaf_flower.jpg (copied directly from the echo command)

path in 'my computer' view - plant_web_images\Asclepiadaceae\Cryptostegia_grandiflora_leaf_flower

path in mysql db - Asclepiadaceae/Cryptostegia_grandiflora_leaf_flower

(the beginning 'plant_web_images' & '.jpg' are added by a php concat command in the script)

 

this file displays just fine - plant_web_images/Bignoniaceae/Macfadyena_unguis-cati_leaf.jpg (copied from echo)

path in 'my computer' view - plant_web_images\Bignoniaceae\Macfadyena_unguis-cati_leaf

path in mysql db - Bignoniaceae/Macfadyena_unguis-cati_leaf

 

Here is a list of the files that aren't displaying

 

plant_web_images/Solanaceae/Cestrum_nocturnum_herb

plant_web_images/Solanaceae/Cestrum_nocturnum_herb2

plant_web_images/Solanaceae/Cestrum_nocturnum_herb3

plant_web_images/Apocynaceae/Pentalinon_luteum_flower.jpg

plant_web_images/Apocynaceae/Pentalinon_luteum_flower2.jpg

plant_web_images/Asclepiadaceae/Cryptostegia_grandiflora_leaf_flower.jpg

plant_web_images/Verbenaceae/Stachytarpheta_jamaicensis_flower2.jpg

plant_web_images/Verbenaceae/Stachytarpheta_jamaicensis_flower3.jpg

plant_web_images/Asclepiadaceae/Cryptostegia_grandiflora_leaf_flower.jpg

 

Is there a hidden reserved word in these or something??  I can't find it if so.

 

Kate

 

 

 

 

Link to comment
Share on other sites

Sorry about the double message I must have hit post by accident before completion.

 

Code for image display:

<?php
session_start();
?>
</head>
<style type="text/css">
#wrapper{
    position: absolute
    top: 0px;
    left: 0px;
    margin: 0px;
    padding: 0px;
    border: 0px;
background-color: #669999;
width: 100%;
height: 100%;
overflow: visible;
}
#navigation {
position: absolute;
top: 0px;
left: 0px;
margin: 0px;
padding: 0px;
border: 0px;
background:#C96;
height: 25px;
width: 100%;
overflow: hidden;
}
#pics {
position: absolute;
top: 26px;
left: 0px;
margin: 0px;
padding: 0px;
border: 0px;
background:#C96;
height: 100%;
width: 100%;
overflow: visible;
}
</style>
<body>
<div id="wrapper">
<div id="navigation"> 
<form action="browser.php" method="post"> 
<input type="submit" name="show" value="escape"> 
<input type="submit" name="show" value="previous"> 
<input type="submit" name="show" value="next"> </form>
</div>
<div id="pics">
<?php
$imagepath = $_SESSION['image_path'];
echo "<img src=\"$imagepath\"/>";
echo $imagepath;
?>
</div>
</div>
</body>
</html>

 

Code for handling images (is in another file)

 

<!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>
<?php
session_start(); // start up PHP session
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
include ("functions.php");
connectto_guana_plants ();
$picstorage = array ();
$imagelocation = "plant_web_images/";
$query = "SELECT serialized FROM serialized_data WHERE title = 'picstorage'";
$result = mysql_query($query) OR die(mysql_error());
$data = mysql_result($result,0);
$picstorage = unserialize($data);
$count = count ($picstorage);
//while (list ($key, $val) = each ($picstorage)) {
//echo "$key -> $val <br>";
//}
//}
//print_r ($picstorage);
$current_url = $_SERVER["PHP_SELF"];
$previous_url = $_SESSION['this_url']; //retrieve data
if ($current_url <> $previous_url) { // so this is the first time through this script
$pic_to_show = 0;
$_SESSION['pic_to_show'] = "0";
$imagename = ($picstorage[0]); // get 1st image name from unserialized picstorage array
$imagepath= $imagelocation.$imagename.'.jpg'; // combine imagelocation & imagename & add .jpg
$_SESSION['image_path'] = "$imagepath";
$this_url = $_SERVER["PHP_SELF"]; //load url for comparison
$_SESSION['this_url'] = "$this_url"; //reasign value of session 'this_url' so next time the script will skip this section
header("Location: http://localhost/Guana_Plant_Key/pic_display.php"); // send user to pic_display
}else{
// branch on the basis of 'show' value
switch ($_POST['show']) {
      // if show => previous
      case 'previous':
  		$pic_to_show = $_SESSION['pic_to_show'];
		$pic_to_show = $pic_to_show - 1;
		if ($pic_to_show < 0) {
		$pic_to_show = $count;
		}
		$_SESSION['pic_to_show'] = "$pic_to_show"; // change session variable pic_to_show to the new value
		$imagename = ($picstorage[$pic_to_show]); // get image name from picstorage array
		$imagepath= $imagelocation.$imagename.'.jpg'; // combine imagelocation & imagename & add .jpg
		$_SESSION['image_path'] = "$imagepath";
		header("Location: http://localhost/Guana_Plant_Key/pic_display.php"); // send user to pic_display
            break;

      // if show => next
      case 'next':
            $pic_to_show = $_SESSION['pic_to_show'];
		$pic_to_show = $pic_to_show + 1;
		if ($pic_to_show > $count) {
		$pic_to_show = 0;
		}
		$_SESSION['pic_to_show'] = "$pic_to_show"; // change session variable pic_to_show to the new value
		$imagename = ($picstorage[$pic_to_show]); // get image name from picstorage array
		$imagepath= $imagelocation.$imagename.'.jpg'; // combine imagelocation & imagename & add .jpg
		$_SESSION['image_path'] = "$imagepath";
		header("Location: http://localhost/Guana_Plant_Key/pic_display.php"); // send user to pic_display
            break;

      // if show => escape
      case 'escape':
            header("Location: http://localhost/Guana_Plant_Key/form_browse.html"); // send user back to form
            break;
}
}
?>
</body>
</html>

 

 

Link to comment
Share on other sites

Us newbies aren't always aware of tabbing conventions.  I will check it out.

 

I thought I was echoing out the url / path.  My page is running on wamp which is just on my computer so I'm not sure what else you mean.

 

I tried entering both bits of code though I am not sure I am using them correctly.  Neither is giving me error messages.

 

I looked up ini_set in the php manual.  I am not sure exactly what it should be doing . . .

 

I could use a bit more of an explanation if someone has a minute.

 

Thanks,

 

Kate

 

 

Link to comment
Share on other sites

I have a feeling this is your problem:

So I am actually selecting the name - in the my computer view & copying them and inserting them into the db.

 

Are you absolutely sure there are no leading or trailing spaces in the value you are pasting into the database???

 

Try this:

<?php
$imagepath = trim($_SESSION['image_path']);
echo "<img src=\"$imagepath\"/>";
echo $imagepath;
?>

 

Although you should really clean up the data in the database if that is the problem.

Link to comment
Share on other sites

The first problem I see with your code is that the "session_start();" line MUST come before any output is sent to the browser. Therefore it's customary to make it the first executable line in the script.

 

You want to change this:

<!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>
<?php
session_start(); // start up PHP session
?>

to

<?php
session_start();
?>
<!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>

 

Ken

Link to comment
Share on other sites

Ken,

 

I fixed all the files with a Session start command so that they come at the very top of the field.  The results are the same but I appreciate any suggestions that make my code better.

 

MJ,

 

I thought of that & in fact I did find a few files that had extra spaces but they were easy to spot when the path echoed & easy to fix.  I did all the easy ones.  I am just stuck on these few.  I did put your code in just in case & it is doing the same thing.

 

I don't know what my next step should be to try to fix this.  Any suggestions?

 

Kate

Link to comment
Share on other sites

Dark,

 

Thanks for sticking with me on this one.

 

The code for the displaying is in one of my posts above.  The bottom code is the one that gets the path name and the top one is the one that displays it. 

 

I hope that what you wanted.

 

K-

Link to comment
Share on other sites

Well another NewBee mistake  ::).  I went to save the file & its a gif so no wonder it wasn't being found as a jpeg.  I swear I checked on that earlier because it was one of the first things I thought of but I must not have for all of them.  I will go check them all & make sure there is no mystery left before I mark this as solved but I am pretty sure it is.

 

Thanks,

 

Kate

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.