Page 1 of 1
PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 7:52 am
by nyo
I am at
Part 2, 03:40, everything works fine up to now.
I don't get that error when I type
http://localhost/resimler.php?img=gallery.php on the address bar, it shows nothing. I have the same code with you.
P.S.
resimler.php has an include to
gallery.php maybe this is the problem...
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 8:04 am
by ta2shop
nailyener wrote:P.S. resimler.php has an include to gallery.php maybe this is the problem...
well if you think that may by the problem, commented out or remouvet, ee what hapens, if the error stil shows, you can putet back.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 8:22 am
by nyo
Well, resimler.php includes gallery.php, so I cannot comment it out.
resimler.php:
<?php include 'includes/header.php'; ?>
<div id="title">Images</div>
<div id="content">
<?php include 'gallery/gallery.php'; ?>
</div>
<?php include 'includes/footer.php'; ?>
gallery.php:
<?php
//checks if the image get variable is set
if (isset($_GET['img'])) {
//creates thumbnails
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('Not an image.');
}
$thumb_width = 100;
$thumb_height = 100;
}
die();
}
//creates thumbs folder if it doesn't exist
if (is_dir('gallery/thumbs') == false) {
mkdir('gallery/thumbs', 0744);
}
//stores the image files in glob array
$images = glob('gallery/'.'*.{jpg,jpeg,png,gif,bmp}', GLOB_BRACE);
//displays all thumbnails if they exist, if not display the image file names
foreach ($images as $image) {
$image = basename($image);
if (file_exists("gallery/thumbs/{$image}")) {
echo "<a href=''><img src='gallery/thumbs/{$image}' width='' height='' alt='{$image}' /></a>";
} else {
echo "<a href=''><img src='?img={$image}' width='' height='' alt='{$image}' /></a>";
}
}
?>
The exact code with the tutorial, but no error is shown like it shows in the tutorial.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 8:29 am
by nyo
And also, I don't see the image size details when I use
print_r($src_size);
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 8:30 am
by ta2shop
what is the error, that you sould see?
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 8:32 am
by nyo
"That does not look like an image."
It is on 03:43.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 8:47 am
by ta2shop
aha y got you
here
if ($src_size == false) {
die('Not an image.');
}
it sould by
if ($src_size === false) {
die('Not an image.');
}
also here, the same problem
if (is_dir('gallery/thumbs') == false) {
mkdir('gallery/thumbs', 0744);
}
it sould by
if (is_dir('gallery/thumbs') === false) {
mkdir('gallery/thumbs', 0744);
}
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 8:52 am
by nyo
Thanks but it is not the issue. There is no difference between "===" and "==" in my case. I tried it to be sure, no difference.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 8:56 am
by Tino
I doubt that is the problem. == simply checks for equality, === checks if they're the same data type too. So that almost can't possibly cause this.
What can, however, is this: the value you give to $_GET['img']. If it's gallery.php as in the video, then you should be seeing that error, meaning there is actually no problem at all!
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 9:06 am
by nyo
Tino wrote:I doubt that is the problem. == simply checks for equality, === checks if they're the same data type too. So that almost can't possibly cause this.
What can, however, is this: the value you give to $_GET['img']. If it's gallery.php as in the video, then you should be seeing that error, meaning there is actually no problem at all!
Yes, I use
http://localhost/resimler.php?img=gallery.php but it doesn't show the error, that means problem. Additionally, print_r($src_size); doesn't show the image info array.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 9:13 am
by Tino
$src_size won't have anything in it because it's impossible to get the image size of a PHP file.
What do you get if you use
echo gettype($src_size);
?
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 9:14 am
by jacek
Are the images in the same folder as the script that includes the gallery script, or in a sub folder ?
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Tue May 10, 2011 9:19 am
by nyo
Tino wrote:$src_size won't have anything in it because it's impossible to get the image size of a PHP file.
What do you get if you use
echo gettype($src_size);
?
I got nothing.
Yes, they are in the same folder. Images and gallery.php are in the same folder.
C:\Apache2\htdocs\gallery\gallery.php
C:\Apache2\htdocs\gallery\img1.jpg
C:\Apache2\htdocs\gallery\img2.jpg etc
and
C:\Apache2\htdocs\resimler.php
has an include to gallery.php
I am just trying to follow the tutorial but I am getting stuck every minute. I use the same code with the tutorial, the only diffeence is that I am running resimler.php which has an include to gallery.php.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Thu May 12, 2011 12:59 am
by GenSwat
nailyener wrote:Well, resimler.php includes gallery.php, so I cannot comment it out.
resimler.php:
<?php include 'includes/header.php'; ?>
<div id="title">Images</div>
<div id="content">
<?php include 'gallery/gallery.php'; ?>
</div>
<?php include 'includes/footer.php'; ?>
gallery.php:
<?php
//checks if the image get variable is set
if (isset($_GET['img'])) {
//creates thumbnails
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('Not an image.');
}
$thumb_width = 100;
$thumb_height = 100;
}
die();
}
//creates thumbs folder if it doesn't exist
if (is_dir('gallery/thumbs') == false) {
mkdir('gallery/thumbs', 0744);
}
//stores the image files in glob array
$images = glob('gallery/'.'*.{jpg,jpeg,png,gif,bmp}', GLOB_BRACE);
//displays all thumbnails if they exist, if not display the image file names
foreach ($images as $image) {
$image = basename($image);
if (file_exists("gallery/thumbs/{$image}")) {
echo "<a href=''><img src='gallery/thumbs/{$image}' width='' height='' alt='{$image}' /></a>";
} else {
echo "<a href=''><img src='?img={$image}' width='' height='' alt='{$image}' /></a>";
}
}
?>
The exact code with the tutorial, but no error is shown like it shows in the tutorial.
I am wondering about the die(), on line 14 and another on die()line 20, wouldn't this one on line 20 kill the script?
Re: PHP Tutorial: Automatic Image Gallery [part 02]
Posted: Thu May 12, 2011 9:33 am
by jacek
It would yeah, but the idea is that the thumbnail is created first