PHP Tutorial: Automatic Image Gallery [part 02]

Post here is you are having problems with any of the tutorials.
Post Reply
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

PHP Tutorial: Automatic Image Gallery [part 02]

Post 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...
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post 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.
Image
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post by nyo »

Well, resimler.php includes gallery.php, so I cannot comment it out.

resimler.php:
[syntax=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'; ?>[/syntax]

gallery.php:
[syntax=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>";
}
}

?>[/syntax]

The exact code with the tutorial, but no error is shown like it shows in the tutorial.
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post by nyo »

And also, I don't see the image size details when I use
[syntax=php]print_r($src_size);[/syntax]
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post by ta2shop »

what is the error, that you sould see?
Image
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post by nyo »

"That does not look like an image."

It is on 03:43.
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post by ta2shop »

aha y got you :lol: :lol:
here
[syntax=php]
if ($src_size == false) {
die('Not an image.');
}
[/syntax]
it sould by
[syntax=php]
if ($src_size === false) {
die('Not an image.');
}
[/syntax]
also here, the same problem
[syntax=php]
if (is_dir('gallery/thumbs') == false) {
mkdir('gallery/thumbs', 0744);
}
[/syntax]
it sould by
[syntax=php]
if (is_dir('gallery/thumbs') === false) {
mkdir('gallery/thumbs', 0744);
}
[/syntax]




;)
Image
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post 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.
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post 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!
Please check out my CodeCanyon items.
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post 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.
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post 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

[syntax=php]echo gettype($src_size);[/syntax]

?
Please check out my CodeCanyon items.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post by jacek »

Are the images in the same folder as the script that includes the gallery script, or in a sub folder ?
Image
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post 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

[syntax=php]echo gettype($src_size);[/syntax]

?


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.
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post by GenSwat »

nailyener wrote:Well, resimler.php includes gallery.php, so I cannot comment it out.

resimler.php:
[syntax=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'; ?>[/syntax]

gallery.php:
[syntax=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>";
}
}

?>[/syntax]

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?
One of my Favorites
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP Tutorial: Automatic Image Gallery [part 02]

Post by jacek »

It would yeah, but the idea is that the thumbnail is created first :)
Image
Post Reply