kate_rose Posted June 26, 2008 Share Posted June 26, 2008 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 - Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2008 Share Posted June 26, 2008 We need to see code. Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 26, 2008 Author Share Posted June 26, 2008 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 Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 26, 2008 Author Share Posted June 26, 2008 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> Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 Why don't people follow proper tabbing convetions. :-\ Try echoing out the url to the picture and going to it directly, and debug from there. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 26, 2008 Share Posted June 26, 2008 ini_set('error_reporting',E_ALL); tell us what you get also try putting <?php $session_id= session_id(); session_start(); if ($session_id=="") { session_start();}?> Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 27, 2008 Author Share Posted June 27, 2008 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 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 27, 2008 Share Posted June 27, 2008 basically if the session is empty it will start the session was abit of code i got off the manual also the in_set code is error reporting it should be producing errors if they are any Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 27, 2008 Share Posted June 27, 2008 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. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 27, 2008 Share Posted June 27, 2008 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 Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 27, 2008 Author Share Posted June 27, 2008 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 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 27, 2008 Share Posted June 27, 2008 Kate, it looks once the image path is defined and setup in that file it redirects to another file to output. if this is correct can we see those files. -thanks Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 27, 2008 Author Share Posted June 27, 2008 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- Quote Link to comment Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 Are you sure these few images that wont display actually exist? Try using an if statement an the file_exists() function to check the image before you assign it to the session variable. This might help. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 28, 2008 Share Posted June 28, 2008 Example Code: <?php if(file_exists($imagepath)) { $_SESSION['image_path']="$imagepath"; }else{ echo "file does not exist"; }?> Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 28, 2008 Author Share Posted June 28, 2008 I really doubt that the file doesn't exist because I can go to the folder on my hard drive click on it & have it open in the image viewer. I will give it a shot though. K- Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 28, 2008 Author Share Posted June 28, 2008 Well the computer thinks the file does not exist but I can't figure out why given that I can go & look at it. I think I will try resaving it under a different name maybe my hard drive is unhappy . . . BRB K- Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 28, 2008 Author Share Posted June 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
kate_rose Posted June 28, 2008 Author Share Posted June 28, 2008 Well not all of them are gifs so maybe we are back to . Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 29, 2008 Share Posted June 29, 2008 can we see the current code? -darkfreaks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.