Home News Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | PHP Code - Print Filename Under Image


You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > Internet Discussion

PHP Code - Print Filename Under Image
Reply
 
Thread Tools
Old 24-08-2010, 17:14   #1
JediMaster
Use The Force
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
Question 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.
JediMaster is offline   Reply With Quote
Old 24-08-2010, 20:01   #2
punky
Gone
Alpha Bravo Charlie Champion
 
Join Date: Jun 2003
Age: 30
Posts: 14,760
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: PHP Code - Print Filename Under Image

You can do a str_replace('_thumbnail.jpg', '',$string)
punky is offline   Reply With Quote
Old 24-08-2010, 22:10   #3
funkyCable
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
funkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nice
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)
funkyCable is offline   Reply With Quote
Old 25-08-2010, 16:10   #4
JediMaster
Use The Force
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
Re: PHP Code - Print Filename Under Image

Quote:
Originally Posted by punky View Post
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 . '
JediMaster is offline   Reply With Quote
Old 25-08-2010, 16:38   #5
Graham M
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+ V-Box VM 10MBit
Posts: 12,820
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
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
Graham M is online now   Reply With Quote
Old 25-08-2010, 17:06   #6
JediMaster
Use The Force
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
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";

?>
JediMaster is offline   Reply With Quote
Old 25-08-2010, 17:13   #7
Graham M
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+ V-Box VM 10MBit
Posts: 12,820
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
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
Graham M is online now   Reply With Quote
Old 25-08-2010, 18:10   #8
JediMaster
Use The Force
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
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";

?>
JediMaster is offline   Reply With Quote
Old 25-08-2010, 18:20   #9
Graham M
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+ V-Box VM 10MBit
Posts: 12,820
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
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
Graham M is online now   Reply With Quote
Old 26-08-2010, 09:17   #10
JediMaster
Use The Force
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
Re: PHP Code - Print Filename Under Image

Quote:
Originally Posted by Graham M View Post
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
JediMaster is offline   Reply With Quote
Old 12-10-2010, 16:37   #11
JediMaster
Use The Force
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
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
JediMaster is offline   Reply With Quote
Old 12-10-2010, 17:09   #12
Graham M
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+ V-Box VM 10MBit
Posts: 12,820
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
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
Graham M is online now   Reply With Quote
Old 12-10-2010, 17:41   #13
JediMaster
Use The Force
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
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.
JediMaster is offline   Reply With Quote
Old 12-10-2010, 18:15   #14
Graham M
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+ V-Box VM 10MBit
Posts: 12,820
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
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

PHP Code:
sort($files); 
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.
Graham M is online now   Reply With Quote
Old 13-10-2010, 00:02   #15
Graham M
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 26
Services: Sky+ V-Box VM 10MBit
Posts: 12,820
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Graham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny starGraham M has a nice shiny star
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
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
Graham M is online now   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Google Search




All times are GMT +1. The time now is 12:14.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Copyright © 2003 - 2012, Cable Forum.
(server1.cableforum.co.uk)

SEO by vBSEO 3.3.2