photo gallery

Ask about a PHP problem here.
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

photo gallery

Post by Robbedoesie »

Hello,
in this photo gallery I am trying to get the thumbnails and full image on the same page but it is not working good.
This is the address of my site http://www.robcnossen.nl/login/view_alb ... album_id=5.
The design comes later.
Maybe you have seen what the problem is, the full image is not showing up in the rectangle when you open this page and when you click on a thumbnail the full image is showing up but then the thumbnail-box is empty.
When I clicked on a thumbnail the ?album_id=5 part disappears so I am out of this album and the thumbnails are away.

My questions are, how can I display a full image when I open this page and how can I not make the thumbnails disappear when clicking on a thumbnail.

The code is;
<?php 
include 'core/init.php';

if (isset($_GET['album_id'])) {
	$album_id = $_GET['album_id'];
$album_data = album_data($album_id, 'name', 'description');

echo '<h3>', $album_data['name'], '</h3><p>', $album_data['description'], '</p>';

$images = get_images($album_id);
}

<div id="wrap">
<div id="sidebarleft">
<?php
if (empty($images)) {
	echo 'Er zijn geen foto\'s in dit album';
} else {
	foreach ($images as $image) {
		echo'<a href="?full_img=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '" title="" /></a> <a href="delete_image.php?image_id=', $image['id'],'">x</a> ';
	}
}
?>
</div>
<div id="imagecontainer">
  <div id="image">
<?php
$full_image=(isset($_GET['full_img'])) ? $_GET['full_img'] : $images[0];
echo'<a href="?full_img=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="',htmlentities($full_image), '" title="" />';
?>
Maybe not necessary but this is the code to make the albums with;
<?php 
$albums = get_albums();

if (empty($albums)) {
	echo '<p>Je hebt nog geen album</p>';
} else {
	foreach ($albums as $album) {
		echo '<p><a href="view_album.php?album_id=', $album['id'], '">', $album['name'], '</a> (', $album['count'], ' foto\'s)<br />
', $album['description'], '...<br />
<a href="edit_album.php?album_id=', $album['id'], '">bewerken</a> / <a href="delete_album.php?album_id=', $album['id'], '">Verwijderen</a>		
		</p>';
	}
}
?>


Cheers
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: photo gallery

Post by jacek »

Not really sure what you mean :s To keep the thumbnail visible you would have to include it on the page :?
Image
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

O, that link was pretty useless, sorry about that.
Hopefully this one is better; http://www.robcnossen.nl/login/view_alb ... album_id=5
and makes my questions more understandable.
Thanks
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: photo gallery

Post by jacek »

Ah okay I see now, you would have to create the same thumbnail view on the second page (http://www.robcnossen.nl/login/view_alb ... /5/109.jpg) so if you were to put the code that creates the left panel in a separate file you could then include() that on both pages.
Image
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

It looks if there are two pages involved for viewing the images. In a way that is of course true but the album.php page only creates albums. If I click on an album link, created with this line of code;
echo '<a href="view_album.php?album_id=', $album['id'], '">';
It sends me to the view_album.php page. This will show up in the address bar;
"http://robcnossen.nl/login/view_album.php?album_id=5".

We are now inside an album and we can click on a thumbnail. The album_id=5 will say that this album is the fifth album that I created. Now I want to show the full image on the same page as the thumbnails, but when I click on a thumbnail the full image appears and the thumbnails disappears. In the address bar this shows up;
http://robcnossen.nl/login/view_album.p ... /5/109.jpg.
So the full image have shown up but I think that I kicked myself out of the album. This part "?full_img=uploads/5/109.jpg"(the full image) replaced this part "?album_id=5".

I am now trying to keep the album and full image parts together but not with any success.
I think that the address bar must be look for example like this,
"http://robcnossen.nl/login/view_album.p ... /5/109.jpg".
But I am not sure that this is possible.

I tried to get the albums part in the view_album.php for example like this;
<?php 
include 'core/init.php';

if (isset($_GET['album_id'])) {
	$album_id = $_GET['album_id'];
$album_data = album_data($album_id, 'name', 'description');

echo '<h3>', $album_data['name'], '</h3><p>', $album_data['description'], '</p>';

$albums = get_albums();
$images = get_images($album_id);
}
?>

<div id="wrap">
<div id="sidebarleft">
<?php

if (empty($images)) {
	echo 'Er zijn geen foto\'s in dit album';
} else { 
if (isset($albums)){
foreach ($albums as $album) {
		echo '<a href="?album_id=', $album['id'], '">';
               }
	}
}
 {
	foreach ($images as $image) {
		echo'<a href="?full_img=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '" title="" /></a> <a href="delete_image.php?image_id=', $image['id'],'">x</a> ';
	}
}
?>
</div>
<div id="imagecontainer">
  <div id="image">
<?php
$full_image=(isset($_GET['full_img'])) ? $_GET['full_img'] : $images[0];
echo'<a href="?full_img=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="',htmlentities($full_image), '" title="" />';
?>
But as I was saying, not with any success.

I hope that you can understand this explanation, it is quite a long explanation, an can help me here.
If you need more code or whatever, let me know.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: photo gallery

Post by jacek »

You can use multiple $_GET variables by separating them with a &, like this "http://robcnossen.nl/login/view_album.php?album_id=5[b]&[/b]full_img=uploads/5/109.jpg".
Image
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

I'm still trying to show the main image on the same page as the thumbnails but it is not working.
In the albums.php the code is now;
<?php 
include 'core/init.php';
protect_page();
include 'template/header.php';
?>
<h3>Albums</h3>
<?php
$albums = get_albums();
if (isset($_GET['album_id'])){
$images = get_images($album_id);
}
if (empty($albums)) {
	echo '<p>Je hebt nog geen album</p>';
} else {
	//if there is an image inside the album, get the image
	if (!empty($images)){
		foreach ($images as $image){
		(isset($_GET['image_id'])) ? $_GET['image_id'] : $images[0];
	}
}{
	foreach ($albums as $album) {
		//show images inside an album		
		echo '<p><a href="view_album.php?album_id=', $album['id'],'&image_id=' ,$image['album'], '/', $image['id'], '.', $image['ext'], '">', $album['name'], '</a> (', $album['count'], ' foto\'s)<br />
', $album['description'], '...<br />
<a href="edit_album.php?album_id=', $album['id'], '">bewerken</a> / <a href="delete_album.php?album_id=', $album['id'], '">Verwijderen</a>		
		</p>';
		}
	}
}
?>
But nothing changes except that I get messages in the address barr like this;
http://www.robcnossen.nl/login/view_alb ... Cbr%20/%3E.

My plan is to get inside the album with the foreach ($images as $image) loop and if there is an image in the album that I show an image.
I think that I'm not even reach an image maybe because I do something wrong with the foreach loop my plan is not right(maybe complete wrong :( ), and if I reach an image how can I get that image on the spot where I want it via view_album.php?
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

Forget my last post, completely wrong thinking, in albums.php are no images so not smart thinking. I am now trying to keep the album_id with the image_id in view_album.php.

In view_albums.php the code is now;
<?php 
include 'core/init.php';

if (isset($_GET['album_id'])) {
	$album_id = $_GET['album_id'];
$album_data = album_data($album_id, 'name', 'description');

echo '<h3>', $album_data['name'], '</h3><p>', $album_data['description'], '</p>';

$albums = get_albums();
$images = get_images($album_id);
}
?>

<title>Untitled Document</title>
</head>

<body>
<div id="wrap">
<div id="sidebarleft">
<?php

if (empty($images)) {
	echo 'Er zijn geen foto\'s in dit album';
} else {
	foreach ($albums as $album) {
	foreach ($images as $image) {
		echo'<a href="view_album.php?album_id=', $album['id'],'&image_id=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '" title="" /></a> <a href="delete_image.php?image_id=', $image['id'],'">x</a> ';
	}
	}
}
?>
</div>
<div id="imagecontainer">
  <div id="image">
<?php
$full_image=(isset($_GET['image_id'])) ? $_GET['image_id'] : $images[0];
echo'<a href="uploads/',$image['album'], '/', $image['id'], '.', $image['ext'],  '"><img src="',htmlentities($full_image), '" title="" />';
?>
</div>
</div>
<div id="footer">
<?php
include 'template/footer.php';
?>
</div>
</div>
</body>
</html>
Which result in;http://www.robcnossen.nl/login/view_alb ... album_id=5.
When you click on a thumbnail the main image shows up on the right spot on the same page as the thumbnails. That's good.

Only all the thumbnails are repeating themselves, how can I stop this?
And how can can I set a default so when I open this album that a main image is showing up right away?
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: photo gallery

Post by ExtremeGaming »

<?php 
	foreach ($albums as $album) {
	foreach ($images as $image) {
		echo'<a href="view_album.php?album_id=', $album['id'],'&image_id=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '" title="" /></a> <a href="delete_image.php?image_id=', $image['id'],'">x</a> ';
	}
	}
?>
Why are you looping inside of a loop? I believe that is the source of your error.
<?php while(!$succeed = try()); ?>
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

I think so too, but there can be more than one albums and more than one image to choose from, so I think I need both foreach loops.

I think that the problem is the album foreach loop, in there are stored the thumbnails, and I don't know how to stop that they repeating themselves. The image foreach loop works fine.
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

Oke, the thumbnails are not repeating themselves anymore, but too get the main image shown up when opening this page is a more difficult question for me.
This is the code in where I try to get the main image in;
<div id="sidebarleft">
<?php

if (empty($images)) {
	echo 'Er zijn geen foto\'s in dit album';
} else {
	foreach ($albums as $album) {
		$image = true;
	foreach ($images as $image) {		
		echo'<a href="view_album.php?album_id=', $album['id'],'&image_id=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '" title="" /></a> <a href="delete_image.php?image_id=', $image['id'],'">x</a> ';
		$image = false;
	}
	if(!$image) break;
	}
}
?>
</div>
<div id="imagecontainer">
  <div id="image">
<?php
$full_image=(isset($_GET['album_id']) && (isset($_GET['image_id']))) ? $_GET['image_id'] : $images[0];
echo'<a href="',$album['id'],'uploads/',$image['album'], '/', $image['id'], '.', $image['ext'],  '"><img src="',htmlentities($full_image), '" title="" />';
?>
</div>
In the div container "imagecontainer" I think I'll have to be. In this case I try to get the album id and image id, set the images default on zero and echo the album and image out. But whit no success at all. I don't come any further here and I hope you can help me out here.
Thanks...
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

If I open the view_album.php page I see on the place where the main image should be a broken image icon(I think that it a broken image icon is). If I click on this icon this message appears; Forbidden
You don't have permission to access /uploads// on this server. I set the permissions for this folder on 755 and in the folder I have a .htaccess file in Options -Indexes in it.

Could that be the problem and is maybe the code correct?
The page is http://www.robcnossen.nl/view_album.php?album_id=7
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: photo gallery

Post by jacek »

I see a php error in your HTML :P
<a href="uploads//."><img src="<br />
<b>Warning</b>:  htmlentities() expects parameter 1 to be string, array given in <b>/data/home/cnos01/domains/robcnossen.nl/public_html/view_album.php</b> on line <b>99</b><br />
" title="" /></div>
Image
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

Do you see that in your browser? Why don't I see that, it only tells me that I don't have access to the folder uploads.

That warning means that it can't reach an image maybe because of a syntax error, doesn't it? Where must I look for the error, is that on line 99, it looks alright to me, but that is not a guarantee.
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

I can see that I get the right data from the array with print_r,
http://www.robcnossen.nl/view_album.php?album_id=7,
but not the image that belong with it, is that because of that warning? Do I then have to convert an array to a string?
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: photo gallery

Post by ExtremeGaming »

You are breaking up the array ($images) with a foreach. Then later down using htmlentities($full_image).

$full_image is sourcing the array which I believe is the source of your error I'm not too sure tbh.
<?php while(!$succeed = try()); ?>
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

Good be, but also I am not sure about that. I did print_r($full_image); and the right data came out for example;
Array ( [id] => 122 [name] => KONICA MINOLTA DIGITAL CAMERA_1043.jpg [album] => 7 [timestamp] => 1355299786 [ext] => jpg )

But maybe the image is not showing because somehow I don't have permission to access the upload folder which I don't understand because I chmod the folder uploads 755 like this;
function create_album($album_name, $album_description) {
	$album_name = mysql_real_escape_string (htmlentities($album_name));
	$album_description = mysql_real_escape_string (htmlentities($album_description));
	
	mysql_query("INSERT INTO `albums` VALUES ('', '".$_SESSION['user_id']."', UNIX_TIMESTAMP(), '$album_name', '$album_description')");
	mkdir('uploads/'.mysql_insert_id(), 0755);
	mkdir('uploads/thumbs/'.mysql_insert_id(), 0755);
}
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

Here I am again, I hope you all are not getting tired of me.

I am not getting to the point where I want to be, so still no main image when you open the view_album.php page.
Jacek,I hope that the php error where you point me at is gone, but I'm not sure that it is gone. I used the implode function for that.

I think now that the main problem is that I use two foreach loops. With only the images foreach loop I can reach the uploads folder. With also the album foreach loop I don't get permission for the uploads folder.

Is there a better way then to use these two foreach loops together like this?
view_album.php;
<?php 
include 'core/init.php';

if (isset($_GET['album_id'])) {
	$album_id = $_GET['album_id'];
$album_data = album_data($album_id, 'name', 'description');

echo '<h3>', $album_data['name'], '</h3><p>', $album_data['description'], '</p>';

$albums = get_albums();
$images = get_images($album_id);

}
?>
<title>Untitled Document</title>
</head>

<body>
<div id="wrap">
<div id="sidebarleft">
<?php

if (empty($images)) {
	echo 'Er zijn geen foto\'s in dit album';
} else {
	foreach ($albums as $album) {
		$image = true;
	foreach ($images as $image) {		
		echo'<a href="view_album.php?album_id=', $album['id'],'&image_id=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '" title="" /></a><a href="delete_image.php?image_id=', $image['id'],'">x</a> ';
		$image = false;
	}
	if(!$image) break;
	implode(",",$images);
	}
}
?>
</div>
<div id="imagecontainer">
  <div id="image">
<?php
$full_image=( chmod('uploads/',755));
$full_image=(isset($_GET['image_id'])) ? $_GET['image_id'] : $images[0];

echo'<a href="uploads/',$image['album'], '/', $image['id'], '.', $image['ext'],  '"><img src="',htmlentities($full_image), '" title="" />';

?>
</div>
</div>
<div id="footer">
<?php
include 'template/footer.php';
?>
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: photo gallery

Post by ExtremeGaming »

The htmlentities error is still there, just view the source of your page. Just for clarification, both the folder and files have 755 permission?
<?php while(!$succeed = try()); ?>
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: photo gallery

Post by jacek »

ExtremeGaming wrote:You are breaking up the array ($images) with a foreach. Then later down using htmlentities($full_image).

$full_image is sourcing the array which I believe is the source of your error I'm not too sure tbh.
This is exactly it, you can't htmlentities an array, you want one specific key from that array. Most likely the name.
Image
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

Aha, of course, the error is shown in the page source.
The htmlentities error is still there, just view the source of your page. Just for clarification, both the folder and files have 755 permission?

The uploads and thumbs folders have 755 permission, the images itself have 644 permission. I removed the .htaccess file to see if that was the problem but it didn't make any changes.

The htmlentities error is gone, I used the id of the image because that is shown in the url
htmlentities($full_image['id'])
. At least, when it shows up. When I click on the id number in the page source an 500 Internal Server Error shows up. Is that because there is no permission to access the uploads folder and everything behind that?

Thanks for helping me...
Post Reply