Joey46 Posted November 10, 2008 Share Posted November 10, 2008 I have worked out how to upload my images but now i need to show the images any ideas please? Link to comment Share on other sites More sharing options...
Synook Posted November 10, 2008 Share Posted November 10, 2008 Use the <img /> tag? Link to comment Share on other sites More sharing options...
Joey46 Posted November 10, 2008 Author Share Posted November 10, 2008 Use the <img /> tag?Sorry i do not understand it that a string or a function ? Link to comment Share on other sites More sharing options...
Synook Posted November 10, 2008 Share Posted November 10, 2008 You display images in HTML. In HTML, the img tag displays an image. Link to comment Share on other sites More sharing options...
Joey46 Posted November 10, 2008 Author Share Posted November 10, 2008 You display images in HTML. In HTML, the img tag displays an image.yes i know that but we have to have a php page that loads the images i do have some of the php code but it will not load my images onto the html page Link to comment Share on other sites More sharing options...
Synook Posted November 10, 2008 Share Posted November 10, 2008 Well, you find out the URL of the image, through glob() for example, and then you echo. echo "<img src=\"$image\" alt=\"image\" />"; What code do you have currently? Link to comment Share on other sites More sharing options...
Joey46 Posted November 10, 2008 Author Share Posted November 10, 2008 Well, you find out the URL of the image, through glob() for example, and then you echo.echo "<img src=\"$image\" alt=\"image\" />"; What code do you have currently? this is my code<?phpfunction imagecreatefromfile($path, $user_functions = false){ $info = @getimagesize($path); if(!$info) { return false; } $functions = array( IMAGETYPE_GIF => 'imagecreatefromgif', IMAGETYPE_JPEG => 'imagecreatefromjpeg', IMAGETYPE_PNG => 'imagecreatefrompng', IMAGETYPE_jpg => 'imagecreatefromjpg', ); if($user_functions) { $functions[iMAGETYPE_BMP] = 'imagecreatefrombmp'; } if(!$functions[$info[2]]) { return false; } if(!function_exists($functions[$info[2]])) { return false; } return $functions[$info[2]]($path);}?> Link to comment Share on other sites More sharing options...
Synook Posted November 10, 2008 Share Posted November 10, 2008 Oh I see... somehow I don't think that last bit will work, you have to do return eval("{$functions[$info[2]]}($path);"); After you have generated the image you just need to echo it, through something like imagepng(), after setting header("content-type:image/png");. The image has to be in a file of its own, which is then called from another text/html page through the img tag, e.g. <img src="image.php" alt="PHP generated image" /> Link to comment Share on other sites More sharing options...
Joey46 Posted November 10, 2008 Author Share Posted November 10, 2008 Oh I see... somehow I don't think that last bit will work, you have to doreturn eval("{$functions[$info[2]]}($path);"); After you have generated the image you just need to echo it, through something like imagepng(), after setting header("content-type:image/png");. The image has to be in a file of its own, which is then called from another text/html page through the img tag, e.g. <img src="image.php" alt="PHP generated image" /> Thank you i will try it in the morning much aprreciated Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 Sorry but that did not work either I have sit here for 5 or 6 hous trying different things but no luck with any of them i'm afraid Link to comment Share on other sites More sharing options...
MinusMyThoughts Posted November 11, 2008 Share Posted November 11, 2008 What is the path you're passing?When you upload the image, how are you saving it?The method I've always used is to process the uploaded file and use move_uploaded_file() to put it in a folder so you can just return the path, save it to your database, and forget about all the complicated headers and other things that come with PHP-generated images.I'd say that's your best bet.-Jason Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 What is the path you're passing?When you upload the image, how are you saving it?The method I've always used is to process the uploaded file and use move_uploaded_file() to put it in a folder so you can just return the path, save it to your database, and forget about all the complicated headers and other things that come with PHP-generated images.I'd say that's your best bet.-JasonHi Jason,It is not a database mate it is 3 pages html 3 pages php to show images, image file names, and delete images Link to comment Share on other sites More sharing options...
Synook Posted November 11, 2008 Share Posted November 11, 2008 How are you trying to show the images currently? You need to have two pages, one that generates the image code and serves it with an image MIME type, and a HTML page that calls the image's script inside an img tag. Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 How are you trying to show the images currently? You need to have two pages, one that generates the image code and serves it with an image MIME type, and a HTML page that calls the image's script inside an img tag.I have a html page plus a php page for showing the images but the images still do not show up for me here is my html code<style type="text/css"><!--body,td,th { color: #FFFFCC;}body { background-color: #996666;}a:link { color: #FFFFCC;}.style1 {font-family: Algerian}a:visited { color: #FFFFCC;}--></style></head><body><p>[ <a href="/ICAB5165A_ICAB4220A/main.htm" target="mainFrame">Main Page</a> ] [<a href="/ICAB5165A_ICAB4220A/upload.htm" target="mainFrame"> Upload </a>] <a href="/ICAB5165A_ICAB4220A/Image_Directory.php" target="mainFrame">[</a><a href="/ICAB5165A_ICAB4220A/Index.php" target="mainFrame"> Show Images</a> ] [ Delete Images ] <br></p> <h2 align="center" class="style1">Gallery Images</h2> Link to comment Share on other sites More sharing options...
Synook Posted November 11, 2008 Share Posted November 11, 2008 Where's the bit that actually has the img tag, and can you also post the page that generates the image code? Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 Where's the bit that actually has the img tag, and can you also post the page that generates the image code?the code i downloaded from the web is in php which i placed up yesterday and the only other page i have for it is that html page i just placed up there........even my teacher could not work out why the images will not load Link to comment Share on other sites More sharing options...
Synook Posted November 11, 2008 Share Posted November 11, 2008 Can you post the PHP page's code?Also, you need to call that page in the HTML such: <img src="the-image-script.php" /> Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 Can you post the PHP page's code?Also, you need to call that page in the HTML such:<img src="the-image-script.php" /> PHP CODE<?phpfunction imagecreatefromfile($path, $user_functions = false){ $info = @getimagesize($path); if(!$info) { return false; } $functions = array( IMAGETYPE_GIF => 'imagecreatefromgif', IMAGETYPE_JPEG => 'imagecreatefromjpeg', IMAGETYPE_PNG => 'imagecreatefrompng', IMAGETYPE_jpg => 'imagecreatefromjpg', ); if($user_functions) if(!$functions[$info[2]]) { return false; } if(!function_exists($functions[$info[2]])) { return false; } return eval("{$functions[$info[2]]}($path);"); }?> HTML CODE<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"("content-type:image/jpg/jpeg/gif/png");.<img src="image.php" alt="PHP generated image"/> <title>Image Gallery</title><style type="text/css"><!--body,td,th { color: #FFFFCC;}body { background-color: #996666;}a:link { color: #FFFFCC;}.style1 {font-family: Algerian}a:visited { color: #FFFFCC;}--></style></head><body><p>[ <a href="/ICAB5165A_ICAB4220A/main.htm" target="mainFrame">Main Page</a> ] [<a href="/ICAB5165A_ICAB4220A/upload.htm" target="mainFrame"> Upload </a>] <a href="/ICAB5165A_ICAB4220A/Image_Directory.php" target="mainFrame">[</a><a href="/ICAB5165A_ICAB4220A/Index.php" target="mainFrame"> Show Images</a> ] [ Delete Images ] <br></p> <h2 align="center" class="style1">Gallery Images</h2> Please let me know if i have done anything wrong in either of the codes, Thank you in Advance also Link to comment Share on other sites More sharing options...
Synook Posted November 11, 2008 Share Posted November 11, 2008 Not quite right yet. It is in the PHP code that you set the content-type header, so at the start of image.php write header("content-type:image/png"); or whatever. Secondly, you're not actually creating an image, you are just creating a function that helps create an image. And the image tag should be in your body, like a normal image. Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 Not quite right yet. It is in the PHP code that you set the content-type header, so at the start of image.php write header("content-type:image/png"); or whatever. Secondly, you're not actually creating an image, you are just creating a function that helps create an image. And the image tag should be in your body, like a normal image.so sorry mate but it still is not working i am now getting a box with PHP generated image written on my HTML page and no images yet eitherwould you like the code again?PHP CODE<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>open_image_directory</title><style type="text/css"><!--body { background-color: #996666;}body,td,th { color: #FFFFCC;}.style1 {color: #FFFFCC}--></style>header ("content-type:image/png");</head><body><?php //Open Graphics directory $dir = opendir("Graphics");//List files in Graphics directorywhile (($file = readdir($dir)) !== false) { echo "filename: " . $file . "<br />"; } closedir($dir);?> <div align="center"><a href="/ICAB5165A_ICAB4220A/main.htm" target="mainFrame" class="style1">BACK</a></div>HTML CODE<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"("content-type:image/jpg/jpeg/gif/png");/> <title>Image Gallery</title><style type="text/css"><!--body,td,th { color: #FFFFCC;}body { background-color: #996666;}a:link { color: #FFFFCC;}.style1 {font-family: Algerian}a:visited { color: #FFFFCC;}--></style></head><body><p>[ <a href="/ICAB5165A_ICAB4220A/main.htm" target="mainFrame">Main Page</a> ] [<a href="/ICAB5165A_ICAB4220A/upload.htm" target="mainFrame"> Upload </a>] <a href="/ICAB5165A_ICAB4220A/Image_Directory.php" target="mainFrame">[</a><a href="/ICAB5165A_ICAB4220A/Index.php" target="mainFrame"> Show Images</a> ] [ Delete Images ] <br></p> <h2 align="center" class="style1">Gallery Images</h2> I am sorry for being a pain in the butt but i need to get this working before next Monday if possible Link to comment Share on other sites More sharing options...
jlhaslip Posted November 11, 2008 Share Posted November 11, 2008 As I understand this Topic, you have a folder of images and you are needing a php script to read the folder, displaying the images onto a page? Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 As I understand this Topic, you have a folder of images and you are needing a php script to read the folder, displaying the images onto a page?I have the php script but it does not work eg it does not show the images when called for my codes are on the previous page and i need it finished by next monday i have spent 2 maybe 3 weeks working on this and it still does not work for me and yes thats exactly what my php script needs to do there is no database involved in this.Thank you Link to comment Share on other sites More sharing options...
jlhaslip Posted November 11, 2008 Share Posted November 11, 2008 Here is a script I wrote which does what you want, except it is written to work with the Hoverbox CSS method, so there will be some stuff you don't need, like thumbnails, etc. Modify the script to suit, like the maxnum limit and the randomize feature.Sample Hoverbox in action here: http://jlhaslip.com/hoverbox/ <?phpecho '<ul class="hoverbox">';$max_num = 15;$j=0;$narray = array();$dir = "images/"; // name of the folder where the Thumbnail images are stored$mid_dir = "mid_images/"; // name of the folder where the Mid-sized images are stored$full_dir = "full_images/"; // name of the folder where the Full-sized images are storedif (is_dir($dir) && (is_dir($mid_dir)) && (is_dir($full_dir)) ) { $dh= @opendir($dir) or die("Unable to open $path please notify the administrator. Thank you."); // confirm directories exist while (($file = readdir($dh)) !== false) { // read the entire directory if(($file != '.') && ($file != '..') && (stristr($file,'jpg'))) { //jpg files only $narray[]=$file; $n++; } }if ($n < $max_num) { $max_num = $n; }shuffle( $narray); while ( $j <= $max_num-1) { echo "\t" . '<li><a href="' . $full_dir . $narray[$j] . '" alt="full-size"><img src="' . $dir . $narray[$j] . '" alt="' . $dir . $narray[$j] . '" ><img src="' . $mid_dir . $narray[$j] . '" alt="mid-size" class="preview" /></a></li> ' . "\n\r\t"; $j++; }} else { echo 'There is a problem with the directories. Please Notify the Administrator. Thank You.';} closedir($dh);echo '</ul>';?> google Hoverbox for the original layout and CSS for the Hoverbox design if you need to. Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 Here is a script I wrote which does what you want, except it is written to work with the Hoverbox CSS method, so there will be some stuff you don't need, like thumbnails, etc. Modify the script to suit, like the maxnum limit and the randomize feature.Sample Hoverbox in action here: http://jlhaslip.com/hoverbox/<?phpecho '<ul class="hoverbox">';$max_num = 15;$j=0;$narray = array();$dir = "images/"; // name of the folder where the Thumbnail images are stored$mid_dir = "mid_images/"; // name of the folder where the Mid-sized images are stored$full_dir = "full_images/"; // name of the folder where the Full-sized images are storedif (is_dir($dir) && (is_dir($mid_dir)) && (is_dir($full_dir)) ) { $dh= @opendir($dir) or die("Unable to open $path please notify the administrator. Thank you."); // confirm directories exist while (($file = readdir($dh)) !== false) { // read the entire directory if(($file != '.') && ($file != '..') && (stristr($file,'jpg'))) { //jpg files only $narray[]=$file; $n++; } }if ($n < $max_num) { $max_num = $n; }shuffle( $narray); while ( $j <= $max_num-1) { echo "\t" . '<li><a href="' . $full_dir . $narray[$j] . '" alt="full-size"><img src="' . $dir . $narray[$j] . '" alt="' . $dir . $narray[$j] . '" ><img src="' . $mid_dir . $narray[$j] . '" alt="mid-size" class="preview" /></a></li> ' . "\n\r\t"; $j++; }} else { echo 'There is a problem with the directories. Please Notify the Administrator. Thank You.';} closedir($dh);echo '</ul>';?> google Hoverbox for the original layout and CSS for the Hoverbox design if you need to. Thank you very much i was close to throwing my pc out the door here i will try it and see if it works Link to comment Share on other sites More sharing options...
Joey46 Posted November 11, 2008 Author Share Posted November 11, 2008 Thank you very much i was close to throwing my pc out the door here i will try it and see if it works i get this error message not sure how to fix it though i have tried a few different things and none of which work so far this is the message i am getting "There is a problem with the directories. Please Notify the Administrator. Thank You." Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.