PHP Tutorial: Automatic Image Gallery [part 02]
PHP Tutorial: Automatic Image Gallery [part 02]
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...
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]
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]
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.
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.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
And also, I don't see the image size details when I use
[syntax=php]print_r($src_size);[/syntax]
[syntax=php]print_r($src_size);[/syntax]
Re: PHP Tutorial: Automatic Image Gallery [part 02]
"That does not look like an image."
It is on 03:43.
It is on 03:43.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
aha y got you
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]
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]
Re: PHP Tutorial: Automatic Image Gallery [part 02]
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]
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!
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.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
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]
$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]
?
What do you get if you use
[syntax=php]echo gettype($src_size);[/syntax]
?
Please check out my CodeCanyon items.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
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]
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.
Re: PHP Tutorial: Automatic Image Gallery [part 02]
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
Re: PHP Tutorial: Automatic Image Gallery [part 02]
It would yeah, but the idea is that the thumbnail is created first