visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: PHP - View images ***HELP ME, URGENT***


By: robi U.S.A.  Date: 24/02/2003 00:00:00  English  Points: 20 Status: Answered
Quality : Excellent
I wan't to show one image in page (show_image.php).
Then I want to next and previous image buttons where I can go to the next and previous images.

My images are in one folder, lets say it is C:\user\images\


So, I can print all image filenames from that folder but how can I show 1 image in page and do those next and previous buttons?



And maybe if somebody has time also to paste the code to the index.php were is all thumbnail pictures from folder C:\user\images\.

help please?

Thanks...
By: VGR Date: 24/02/2003 00:02:00 English  Type : Answer
ok, let's go :
1) first you suceeded in getting the list of all files (images/thumbnails) in the directory.
Good.
2) now you've to memorize this list in a PHP array, like this :
$images=array();
// here memorize $images[0...]

This variable has to be registered globally usign session_register() or any other mechanism available for your PHP version and the php.ini ("register_globals="On/Off) settings of your server.

3) given that you start from the first image, or from the one clicked upon in the "view all thumbnails" page (index.php like this :
<?
session_start();
// let's display an array [4,n] of the thumbnails
echo "<html><body>";
// rough
echo "<table>";
echo "<tr>";
for ($i=0;$i<count($images);$i++) {
$locimage=$images[$i]; // name of image[$i], thumbnail is tn_*
echo "<td><a href=\"show_image.php?index=$i\" target=\"\" border=0><img src=\"C:\user\images\tn_$locimage\"></a></td>"; // line is being contructed
if (($i MOD 4)==0) echo "</tr><tr>"; // EoLn
} // for images
echo "</tr></table>";
// end of HTML printout
echo "</body></html>";
?>

)

4) now show_image.php is like this :
<?
session_start(); // enables us to use $images[]
// $index is transmitted via the URL (register_globals= On, or play childish game with $_POST[] "superglobal")
// let's print the image and provide previous and next "buttons"
echo "<html><body>";
// let's center everything
echo "<center>";
// the image
$locimage=$images[$index];
echo "<img src=\"C:\user\images\$locimage\">";
// skip two lines and the links
if ($i>0) echo "<a href=$PHP_SELF?index=".($index-1).">previous</a>";
if ($i<count($images)) echo "<a href=$PHP_SELF?index=".($index+1).">next</a>";
// finished
echo "</center>";
echo "</body></html>";
?>
By: RQuadling Date: 24/02/2003 01:29:00 English  Type : Comment
SUPERGLOBALS RULE!!!!

And register_globals is probably going to be removed in later releases of PHP!!!

And you'd use $_GET['index'] not the $_POST[] superglobal.

Richard.

By: VGR Date: 24/02/2003 02:58:00 English  Type : Comment
hu hu hu
By: PHP newbee Date: 24/02/2003 18:38:00 English  Type : Comment
This line won't work:

if (($i MOD 4)==0) echo "</tr><tr>";



And this won't work either:

if (($i MOD 4)==0) { echo "</tr><tr>"; }


ERROR:

PHP Parse error: parse error, unexpected T_STRING in C:\folder\wwwroot\folder\index.php on line 40
By: VGR Date: 25/02/2003 20:21:00 English  Type : Comment
yes, trivially modulo is % not MOD
one of the exceptions of PHP, which offers NOT, OR, AND as alternatives to !, || and && but doesn't for % (MOD) but uses only XOR (no symbol "C-style")

Inconsistency
By: VGR Date: 25/02/2003 20:22:00 English  Type : Comment
when I write, I expect people to know the operators' codes for the language they use. It's sorta algorithm, not a fully "compiled and tested" "program"
I leave 1% of the work to other people, I'm not egoist :D
By: PHP newbee Date: 25/02/2003 21:26:00 English  Type : Comment
hehe, ok :)

Do register to be able to answer

EContact
browser fav
page generated in 346.005920 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page