/    Sign up×
Community /Pin to ProfileBookmark

Getting file name of image

I have a slideshow going and what im trying to do is display the filename of the current image that is showing. How would I do this in php?
Thanks!!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@michael879Mar 04.2007 — what are you using the display the slideshow? Whatever it is, you need the filename to be able to display the picture. That means your script knows the filename. Just output it..
Copy linkTweet thisAlerts:
@prophitauthorMar 04.2007 — This is what im using
<i>
</i>&lt;?php
$dh = new DirectoryIterator( "pics" );

$files = array();
foreach( $dh as $file)
{
if ( preg_match("/[.]jpg$/", $file)) $files []= "$file";
}
?&gt;


&lt;style&gt;
body { background: Black;}
#thumbnails { height: 140px; width: 100%; overflow: auto;}
#pic { text-align: center; height: 400px; padding: 20px;}
&lt;/style&gt;
&lt;script&gt;
var image_list = [
&lt;?php $first = true; foreach( $files as $image) { ?&gt;
&lt;?php echo ($first ? "" : ", "); ?&gt; "&lt;?php echo ($image); ?&gt;"
&lt;?php $first = false;}?&gt;
];

var curimage = 0;

function switchimg( ind )
{
var image = image_list[ind];
var obj = document.getElementById( "selimg" );
obj.src = "scale.php?image="+image+"&amp;y=400";
curimage = ind;
}

function nextimage()
{
curimage++;
if ( curimage &gt;= image_list.length ) curimage = 0;
switchimg( curimage );
}


window.setInterval( "nextimage()", 10000 );
&lt;/script&gt;

&lt;table width="100%"&gt;
&lt;tr&gt;
&lt;?php $ind = 0; foreach ($files as $image) { ?&gt;
&lt;td width="160" nowrap align="center"&gt;
&lt;a href="javascript:switchimg( &lt;?php echo ($ind); ?&gt; )"&gt;
&lt;img height="100" src="scale.php?image=&lt;?php echo ($image); ?&gt;&amp;y=100" border="0" /&gt;
&lt;/a&gt;
&lt;/td&gt;
&lt;?php $ind++; } ?&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td width="830"&gt;
&lt;div id="pic"&gt;
&lt;img id="selimg" height="400" src="scale.php?image=&lt;?php echo ($files[0]);?&gt;&amp;y=400" /&gt;
&lt;br&gt;
&lt;?php

echo '&lt;font color="ffffff"&gt;Filename&lt;/font&gt;';
?&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;



the script uses javascript and php to change the image. I'm just not sure how to pull out the variables to echo or print the filename of the displaying image.
Copy linkTweet thisAlerts:
@michael879Mar 04.2007 — scale.php?image=<?php echo ($image); ?>&y=100

that is the images url..
×

Success!

Help @prophit spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...