PHP Code - Print Filename Under Image
24-08-2010, 17:14
|
#1
|
|
Use The Force
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
|
PHP Code - Print Filename Under Image
I have seen this Script http://www.devtek.org/tutorials/image_gallery.php & it works great for my needs. Display images (Thumbnails) in a GRID. I've edited it to REMOVE Click on Image to see Full Image (as the image is only 200 x 130).
I would love to include under every Thumbnail the JPG name (ie 001.jpg or just 001)
Is there an easy way to do this with Print Command? Any help  Please
Cheers
EDIT: Just added the code [br] & '. $file . ' after the Image & it works... (Great) Hope can I remove the .jpg though?
Say Image are 0001_thumbnail.jpg & I want to REMOVE _thumbnail.jpg off every image?
Last edited by JediMaster; 24-08-2010 at 17:48.
|
|
|
24-08-2010, 20:01
|
#2
|
|
Gone
Join Date: Jun 2003
Age: 30
Posts: 14,760
|
Re: PHP Code - Print Filename Under Image
You can do a str_replace('_thumbnail.jpg', '',$string)
|
|
|
24-08-2010, 22:10
|
#3
|
|
THE FUNKIEST ON THE BOARD
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,147
|
Re: PHP Code - Print Filename Under Image
HI Not sure if you seen this CMS but give it a try if you looking for an image gally. google Zenphoto. its a free php/mysql image gallery.
__________________
Overall Average Speed = approx 132171 Kbps, 2131.42 Mbps (on crack)
|
|
|
25-08-2010, 16:10
|
#4
|
|
Use The Force
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
|
Re: PHP Code - Print Filename Under Image
Quote:
Originally Posted by punky
You can do a str_replace('_thumbnail.jpg', '',$string)
|
Sorry is this what you mean?
$jpg = str_replace('_thumbnail.jpg', '',$string);
Then where I want the Filenames I enter the command '. $jpg . '
|
|
|
25-08-2010, 16:38
|
#5
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+
V-Box
VM 10MBit
Posts: 12,820
|
Re: PHP Code - Print Filename Under Image
Yes correct;
$jpg = str_replace('_thumbnail.jpg', '',$jpg);
str_replace returns a string, the above code would take .jpg and remove any instances of _thumbnail.jpg in the string variable "JPG"
__________________
Desktop: Intel i7 SandyBridge 2600k 3.4GHz @ 4.7GHz - 8GB DDR3 - ATI Radeon HD 5770 1GB - OCZ Agility 3 60GB SSD Laptop: Dell Studio 15 - Intel i3 M350 @ 2.27GHz - 3GB DDR3 - ATI Radeon Mobility 4570
|
|
|
25-08-2010, 17:06
|
#6
|
|
Use The Force
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
|
Re: PHP Code - Print Filename Under Image
This is my CODE...
JPGs are inside my img/ folder (they Load Fine)
The Filenames dont show at all.
Code:
<?php
$jpg = str_replace('_thumbnail.jpg', '',$string);
$images = "img/"; # Location of small versions
$big = "img/"; # Location of big versions (assumed to be a subdir of above)
$cols = 4; # Number of columns to display
if ($handle = opendir($images)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != rtrim($big,"/")) {
$files[] = $file;
}
}
closedir($handle);
}
$colCtr = 0;
echo '<table width="100%" cellspacing="0" cellpadding="0"><tr>';
foreach($files as $file)
{
if($colCtr %$cols == 0)
echo '</tr><tr><td colspan="2"></td></tr><tr>';
echo '<td align="center"><img src="' . $images . $file . '" /><br> '. $jpg . '</td>';
$colCtr++;
}
echo '</table>' . "\r\n";
?>
|
|
|
25-08-2010, 17:13
|
#7
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+
V-Box
VM 10MBit
Posts: 12,820
|
Re: PHP Code - Print Filename Under Image
Well where you've put that line of code, no variable $jpg has been used or initialised
Try
foreach($files as $file)
{
$fullname = str_replace('_thumbnail.jpg', '',$file);
if($colCtr %$cols == 0)
echo '</tr><tr><td colspan="2"></td></tr><tr>';
echo '<td align="center"><img src="' . $images . $file . '" /><br> '. $fullname . '</td>';
$colCtr++;
}
__________________
Desktop: Intel i7 SandyBridge 2600k 3.4GHz @ 4.7GHz - 8GB DDR3 - ATI Radeon HD 5770 1GB - OCZ Agility 3 60GB SSD Laptop: Dell Studio 15 - Intel i3 M350 @ 2.27GHz - 3GB DDR3 - ATI Radeon Mobility 4570
|
|
|
25-08-2010, 18:10
|
#8
|
|
Use The Force
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
|
Re: PHP Code - Print Filename Under Image
Hi Graham. Now page wont load...
Code:
<?php
foreach($files as $file)
{
$fullname = str_replace('_thumbnail.jpg', '',$file);
$images = "img/"; # Location of small versions
$big = "img/"; # Location of big versions (assumed to be a subdir of above)
$cols = 4; # Number of columns to display
if ($handle = opendir($images)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != rtrim($big,"/")) {
$files[] = $file;
}
}
closedir($handle);
}
$colCtr = 0;
echo '<table width="100%" cellspacing="0" cellpadding="0"><tr>';
foreach($files as $file)
{
if($colCtr %$cols == 0)
echo '</tr><tr><td colspan="2"></td></tr><tr>';
echo '<td align="center"><img src="' . $images . $file . '" /><br> '. $fullname . '</td>';
$colCtr++;
}
echo '</table>' . "\r\n";
?>
|
|
|
25-08-2010, 18:20
|
#9
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+
V-Box
VM 10MBit
Posts: 12,820
|
Re: PHP Code - Print Filename Under Image
Errr... I replaced part of your code, didn't tell you to add it, have you tried reading what you've put?
__________________
Desktop: Intel i7 SandyBridge 2600k 3.4GHz @ 4.7GHz - 8GB DDR3 - ATI Radeon HD 5770 1GB - OCZ Agility 3 60GB SSD Laptop: Dell Studio 15 - Intel i3 M350 @ 2.27GHz - 3GB DDR3 - ATI Radeon Mobility 4570
|
|
|
26-08-2010, 09:17
|
#10
|
|
Use The Force
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
|
Re: PHP Code - Print Filename Under Image
Quote:
Originally Posted by Graham M
Errr... I replaced part of your code, didn't tell you to add it, have you tried reading what you've put? 
|
Totally lost me sorry...
Can you explain??
Oops I see... I added the line of code in wrong place :P
Works GREAT Now Cheers
|
|
|
12-10-2010, 16:37
|
#11
|
|
Use The Force
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
|
Re: PHP Code - Print Filename Under Image
Is there a way to list the files in Alphabetical Order ? It seams random at the moment?
Cheers
|
|
|
12-10-2010, 17:09
|
#12
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+
V-Box
VM 10MBit
Posts: 12,820
|
Re: PHP Code - Print Filename Under Image
RTFM
http://php.net/manual/en/function.sort.php
You need to do that on the $files array, give it a go and come back if you're stuck still
__________________
Desktop: Intel i7 SandyBridge 2600k 3.4GHz @ 4.7GHz - 8GB DDR3 - ATI Radeon HD 5770 1GB - OCZ Agility 3 60GB SSD Laptop: Dell Studio 15 - Intel i3 M350 @ 2.27GHz - 3GB DDR3 - ATI Radeon Mobility 4570
|
|
|
12-10-2010, 17:41
|
#13
|
|
Use The Force
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
|
Re: PHP Code - Print Filename Under Image
Hi Graham M. No idea what or where needs editing? I'm new to PHP. Any advice (or answers) would be grateful
So far my code is:
Code:
<?php
$images = "tn_/"; # Location of small versions
$big = "img/"; # Location of big versions (assumed to be a subdir of above)
$cols = 4; # Number of columns to display
if ($handle = opendir($images)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != rtrim($big,"/")) {
$files[] = $file;
}
}
closedir($handle);
}
$colCtr = 0;
echo '<table width="100%" cellspacing="0" cellpadding="0"><tr>';
foreach($files as $file)
{ $fullname = str_replace('.jpg', '',$file);
if($colCtr %$cols == 0)
echo '</tr><tr><td colspan="2"></td></tr><tr>';
echo '<td align="center"><a rel="thumbnail" href="' . $big . $file . '"><img src="' . $images . $file . '" /></a><b><font size="2" face="Arial" color="#000000"><br><a href="http://www.domain.com">View</a><br>ID Code: <font color="#FF0000">'. $fullname . '</font><br><br></font></b></td>';
$colCtr++;
}
echo '</table>' . "\r\n";
?>
Last edited by JediMaster; 12-10-2010 at 18:07.
|
|
|
12-10-2010, 18:15
|
#14
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+
V-Box
VM 10MBit
Posts: 12,820
|
Re: PHP Code - Print Filename Under Image
Well you'll never learn unless you play about with it yourself  Anyhow, the following should help.
Just above the line
PHP Code:
foreach ($files as $file)
Add a new line
No need to self reference this one in the return as it works directly on the array and returns true or false depending on if it's worked
__________________
Desktop: Intel i7 SandyBridge 2600k 3.4GHz @ 4.7GHz - 8GB DDR3 - ATI Radeon HD 5770 1GB - OCZ Agility 3 60GB SSD Laptop: Dell Studio 15 - Intel i3 M350 @ 2.27GHz - 3GB DDR3 - ATI Radeon Mobility 4570
Last edited by Graham M; 12-10-2010 at 18:19.
|
|
|
13-10-2010, 00:02
|
#15
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+
V-Box
VM 10MBit
Posts: 12,820
|
Re: PHP Code - Print Filename Under Image
So did this do what you wanted?
__________________
Desktop: Intel i7 SandyBridge 2600k 3.4GHz @ 4.7GHz - 8GB DDR3 - ATI Radeon HD 5770 1GB - OCZ Agility 3 60GB SSD Laptop: Dell Studio 15 - Intel i3 M350 @ 2.27GHz - 3GB DDR3 - ATI Radeon Mobility 4570
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +1. The time now is 12:14.
|