Problem on PHP Tutorial: Automatic Image Gallery tutorial
-
- Posts: 8
- Joined: Sun Oct 14, 2012 8:45 am
Problem on PHP Tutorial: Automatic Image Gallery tutorial
Hi master's of PHP, I have a problem with one of your tutorials about automatic image galleries.
Maybe its just me, but every time I load the page the error icons show instead of the actual image.
Please help me
Maybe its just me, but every time I load the page the error icons show instead of the actual image.
Please help me
Last edited by Helx on Sun Oct 14, 2012 9:40 am, edited 2 times in total.
Reason: Moved to PHP subforum, more gramatical issues
Reason: Moved to PHP subforum, more gramatical issues
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
Could you right click on the page and click 'view source'
Just paste a snippet of whats there, not the whole thing.
Just paste a snippet of whats there, not the whole thing.
-
- Posts: 8
- Joined: Sun Oct 14, 2012 8:45 am
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
<?php if (isset($_GET['img'])){ if (file_exists($_GET['img'])){ ignore_user_abort(true); set_time_limit(120); ini_set('memory_limit', '512m'); $src_size = getimagesize($_GET['img']); if ($src_size === false){ die ('That does not look like an image'); } $thumb_width = 1100; $thumb_height = 1100; if ($src_size['mime'] === 'image/jpeg'){ $src = imagecreatefromjpeg($_GET['img']); }else if ($src_size['mime'] === 'image/png'){ $src = imagecreatefrompng($_GET['img']); }else if ($src_size['mime'] === 'image/gif'){ $src = imagecreatefromgif($_GET['img']); } $src_aspect = round(($src_size[0] / $src_size[1]), 1); $thumb_aspect = round(($thumb_width / $thumb_height), 1); if ($src_aspect < $thumb_aspect){ //higher $new_size = array($thumb_width, ($thumb_width / $src_size[0]) * $src_size[1]); $src_pos = array(0, ($new_size[1] - $thumb_height) / 2); }else if ($src_aspect > $thumb_aspect){ //wider $new_size = array (($thumb_width / $src_size[1]) * $src_size[0],$thumb_height); $src_pos = array(($new_size[0] - $thumb_width) / 2, 0); }else{ // same shape $new_size = array($thumb_width, $thumb_height); $src_pos = array(0, 0); } if ($new_size[0] < 1) $new_size[0] = 1; if ($new_size[1] < 1) $new_size[1] = 1; $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $src, 0, 0, $src_pos[0], $src_pos[1], $new_size[0], $new_size[1], $src_size[0], $src_size[1]); if ($src_size['mime'] === 'image/jpeg'){ imagejpeg($thumb, "thumbs/{$GET['img']}"); }else if ($src_size['mime'] === 'image/png'){ imagepng($thumb, "thumbs/{$GET['img']}"); }else if ($src_size['mime'] === 'image/gif'){ imagegif($thumb, "thumbs/{$GET['img']}"); } header("Location: thumbs/{$_GET['img']}"); } die(); } if (is_dir('./thumbs') === false){ mkdir('./thumbs', 0744); } $images = glob('*.{jpg,jpeg,png,gif}', GLOB_BRACE); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style stype="text/css"> a, img{float:left;} </style> <title>Image Gallery</title> </head> <body> <div> <?php foreach($images as $image){ if (file_exists("./thumbs{$image}")){ echo "<a href=\"\"><img src=\"images/{$images}\" alt\"{$images}\" /></a>"; }else{ echo "<a href=\"\"><img src=\"?img/{$images}\" alt\"{$images}\" /></a>"; } } ?> </div> </body> </html>I'll just send the codes I copy on tutorial...
Because when I view the source code only the HTML code is shown alongside the alt array thing...
Thanks.
I'm making a photo sharing website and I include this thing into my page so that people, well,
know who's currently registered on my webpage
Thanks
Last edited by Helx on Sun Oct 14, 2012 9:11 am, edited 2 times in total.
Reason: Code tags.. English...
Reason: Code tags.. English...
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
You posted the source of the page them removed it?
Could you please post it again in
Could you please post it again in
tags. I'm having trouble trying to figure out what your problem with this script is
-
- Posts: 8
- Joined: Sun Oct 14, 2012 8:45 am
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style stype="text/css"> a, img{float:left;} </style> <title>Image Gallery</title> </head> <body> <div> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> <a href=""><img src="?img/Array" alt"Array" /></a> </div> </body> </html>
Here it is PHP master!
I removed it because i thought this was like spamming code because its repeating..
Please help me.
I still got a lot of problems like sharing photos in a wall for everybody how to like the picuture and put a comment,
I cant see any tutorials thats why i need to fix this first
Last edited by Helx on Sun Oct 14, 2012 9:38 am, edited 3 times in total.
Reason: Added code tags, fixed pedantic spelling errors
Reason: Added code tags, fixed pedantic spelling errors
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
I'm still a tad unsure,
But try editing line 87;
Try replacing <img src=\"?img/{$images}\" alt\"{$images}\" />
With <img src=\"?img={$images}\" alt\"{$images}\" />
(That was ?img/{$images} to ?img={$images})
Query strings (the question marks in URLs) are not like directories. They use the equals operator.
But try editing line 87;
Try replacing <img src=\"?img/{$images}\" alt\"{$images}\" />
With <img src=\"?img={$images}\" alt\"{$images}\" />
(That was ?img/{$images} to ?img={$images})
Query strings (the question marks in URLs) are not like directories. They use the equals operator.
-
- Posts: 8
- Joined: Sun Oct 14, 2012 8:45 am
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
Still not working, I have same problem with the small icon showing on the page...
Thanks for the reply
Thanks for the reply
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
Hmm,
Get rid of the line with $image in it,
and replace it with
I think the problem was that you needed to state each part of the array, or it will just return the words 'Array".
Get rid of the line with $image in it,
and replace it with
foreach(glob("*.{jpg,JPG,jpeg,JPEG,png,PNG,gif,GIF}", GLOB_BRACE) as $file){ $image[] = basename($file); }And lower down in the file, around line 83 down, change those {$images} to {$image}.
I think the problem was that you needed to state each part of the array, or it will just return the words 'Array".
-
- Posts: 8
- Joined: Sun Oct 14, 2012 8:45 am
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style stype="text/css"> a, img{float:left;} </style> <title>Image Gallery</title> </head> <body> <div> <a href=""> <img src="?img=5054193870_a648423b1e_o.jpg" alt"5054193870_a648423b1e_o.jpg" /></a><a href=""> <img src="?img=5106897146_98edafd5a1_o.jpg" alt"5106897146_98edafd5a1_o.jpg" /></a><a href=""> <img src="?img=5121878938_96735ba65f_o.jpg" alt"5121878938_96735ba65f_o.jpg" /></a><a href=""> <img src="?img=A little motivation 1024x768.jpg" alt"A little motivation 1024x768.jpg" /></a><a href=""> <img src="?img=ACE 1.jpg" alt"ACE 1.jpg" /></a><a href=""> <img src="?img=HOTTEST PAPERS ON THE NET (30).jpg" alt"HOTTEST PAPERS ON THE NET (30).jpg" /></a><a href=""> <img src="?img=Hydrangeas.jpg" alt"Hydrangeas.jpg" /></a><a href=""> <img src="?img=Jellyfish.jpg" alt"Jellyfish.jpg" /></a><a href=""> <img src="?img=Lighthouse.jpg" alt"Lighthouse.jpg" /></a><a href=""> <img src="?img=Untitled-2.jpg" alt"Untitled-2.jpg" /></a><a href=""> <img src="?img=anonymous-mask.jpg" alt"anonymous-mask.jpg" /></a><a href=""> <img src="?img=ep3ace.jpg" alt"ep3ace.jpg" /></a><a href=""> <img src="?img=fischfanger___think-t2.jpg" alt"fischfanger___think-t2.jpg" /></a><a href=""> <img src="?img=graffiti_technica_wallpaper_full.jpg" alt"graffiti_technica_wallpaper_full.jpg" /></a><a href=""> <img src="?img=hybridtech.jpg" alt"hybridtech.jpg" /></a><a href=""> <img src="?img=images.jpg" alt"images.jpg" /></a><a href=""> <img src="?img=micro.jpg" alt"micro.jpg" /></a><a href=""> <img src="?img=rainbow.jpg" alt"rainbow.jpg" /></a><a href=""> <img src="?img=tech.jpg" alt"tech.jpg" /></a><a href=""> <img src="?img=tech1.jpg" alt"tech1.jpg" /></a><a href=""> <img src="?img=tech3.jpg" alt"tech3.jpg" /></a><a href=""> <img src="?img=redline_f.JPG" alt"redline_f.JPG" /></a> </div> </body> </html>
i thnk its almost going fine... now this is the new problem its almost done..
Last edited by Temor on Sun Oct 14, 2012 4:32 pm, edited 1 time in total.
Reason: Tags
Reason: Tags
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
... Is it displaying the images?
-
- Posts: 8
- Joined: Sun Oct 14, 2012 8:45 am
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
only small icons
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
Small icons of the images?
Or the error things?
Or the error things?
-
- Posts: 8
- Joined: Sun Oct 14, 2012 8:45 am
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
small icons like on the first post i made with the attach image..
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
<?php foreach($images as $image){ if (file_exists("./thumbs{$image}")){ echo "<a href=\"\"><img src=\"images/{$images}\" alt\"{$images}\" /></a>"; }else{ echo "<a href=\"\"><img src=\"?img/{$images}\" alt\"{$images}\" /></a>"; } } ?>$images is an array. You need to use $image when you echo.
<?php foreach($images as $image){ if (file_exists("./thumbs{$image}")){ echo "<a href=\"\"><img src=\"images/{$image}\" alt\"{$image}\" /></a>"; }else{ echo "<a href=\"\"><img src=\"?img/{$image}\" alt\"{$image}\" /></a>"; } } ?>I am also fairly sure that you need a slash between thumbs and {$image} here:
if (file_exists("./thumbs{$image}")){don't quote me on that though. Try it for yourself.
-
- Posts: 8
- Joined: Sun Oct 14, 2012 8:45 am
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
i follow all what you have told me but i have still the same problem.. same with the first image post i did...
Re: Problem on PHP Tutorial: Automatic Image Gallery tutoria
If you look at the image location "?img=5054193870_a648423b1e_o.jpg" it looks right, so if you paste that into your browser to actually view the thumbnail it might tell you why it's not generating one.ijohnrussel wrote:i follow all what you have told me but i have still the same problem.. same with the first image post i did...