Closed Thread Icon

Topic awaiting preservation: Finding the name of images in folder (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12670" title="Pages that link to Topic awaiting preservation: Finding the name of images in folder (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Finding the name of images in folder <span class="small">(Page 1 of 1)</span>\

 
CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-26-2003 19:59

Using JavaScript, is there a way to just print to the screen the names of the images in a folder?

Let's say that I have 11 images in a folder, I would like to scan through each one of those images
and write the name of the path and the name of the image. Does that make sense?

What I am wanting to do is for each image in folder (/images) I want JavaScript to write something like

code:
document.write(imageSource + imageName)



where ImageName is the exact name of the image that I have called it and resides in the ImageSource Folder.

I think I am confusing myself

This probably has to be done server-side, if so, please move it.

Thanks in advance for all your help.

Later,

C:\


~Binary is best~

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-26-2003 20:28

someone quick move it




.:[ Never resist a perfect moment ]:.

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-26-2003 22:02

eigh, I knew it was going to be more difficult than I though

Later,

C:\


~Binary is best~

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 03-26-2003 22:07

Moving it on over
Unfortunately I don't have an answer, as this is not an area I have delved into yet...

[This message has been edited by DL-44 (edited 03-26-2003).]

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-27-2003 03:24

I could probably put together a php solution for you if that would help.

Just let me know.

-Butcher-

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-27-2003 14:28

Butcher: Yep, if it's server-side I would much prefer PHP. If it's not too much trouble, that would be great!

Thanks for the offer.

Later,

C:\


~Binary is best~

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-27-2003 20:01

ok, here a quick, dirty, plug in whatever you want solution, untested, but it shouldn't have more than a few obvious (as in missing ; or so) bugs in it ;-)

code:
<?php

$dh = opendir(dirname(__FILE__) . '/mydirectory') // would be mydirectory below the directory this file resides in...

while ($filename = readdir($dh))
{
if ($filename != '.' and $filename != '..')
{
print("document.write(\"http://www.mydomain.com/mydirectory/{$filename}\");"); //this would be the line you'd adjust for your needs... uh. filename will probably not include mydirectory. make sure to escape all but the enclosing " with a backslash.
}
}
closedir($dh);

?>



holler, if you need more help,

Tyberius Prime

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-27-2003 20:59

Thanks a bunch, I will give it a go when I get home.

Thanks again.

Later,

C:\


~Binary is best~

Azazeal
Bipolar (III) Inmate

From:
Insane since: Jun 2002

posted posted 03-28-2003 22:18
code:
<?php
//-- Directory listing - lists the contents of a directory
//-- Azazeal
//-- Created 2.19.03
//-- Modified 3.28.03

//-- User Configured Data
$webaddress = 'http://www.<yoursite>.com/'; //-- Full URL to files folder
$current_dir = 'files';//-- Directory to read
$page_title = '.: :Directory Listing::.'; //-- Title of HTML document

//-- Display file as a link
//-- Change the value to '1' if you want the file to be displayed as a link.
//-- Change the value to '0' if you want the file to NOT be displayed as a link.
$asURL = '0';
//-- End User Configured Data
//-- You shouldn't have to touch anything below this line. Unless you want to format the HTML.
?>
<html>
<head>
<title><?php echo $page_title ?></title>
</head>
<body>
<table width='60%' align='center'>
<tr>
<td>Current directory is <b><?php echo $current_dir ?></b></td>
</tr>
<tr>
<td>Directory contains the following files...</td>
</tr>
<tr>
<td>
<?php
//-- Read the directory and display the results.

$dir = opendir($current_dir);

while($file = (readdir($dir)))
{
if($asURL=='1')
{
if(is_file("$current_dir/$file"))
{
?>
<a href="<?php echo $webaddress;echo $current_dir ?>/<?php echo $file ?>"><?php echo $webaddress;echo $file ?></a><br>
<?php
}
}

if($asURL=='0')
{
if(is_file("$current_dir/$file"))
{
?>
<?php echo $webaddress;echo $file ?><br>
<?php
}
}
}

closedir($dir);
?>
</td>
</tr>
</table>
<hr width='60%'>
<br>
</body>
</html>



Here is something I had come up with a little while back. I added an extra switch $asURL. This is if you want to display the file name as a link or not.


[edit]cleaned the code up...=)[/edit]



[This message has been edited by Azazeal (edited 03-28-2003).]

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 04-01-2003 02:58

Azazeal, thanks. That was a nice script. I didn't have to change much to get it working.

Thanks again.

Later,

C:\


~Binary is best~

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 04-01-2003 09:57

Is there any way TP's solution can be modified to find or sort the files alphabetically?

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 04-01-2003 12:25

Yup...
I rewrote some of the code (hope you don't mind Azazeal)
Now it reads the files into an array, sorts that alphabetically, then loops the
array and prints links or non-links, just as before.

code:
<?php
//-- Directory listing - lists the contents of a directory
//-- Azazeal
//-- Created 2.19.03
//-- Modified 3.28.03
//-- Mod for sorting files alphabetically //DmS 1.4.03

//-- User Configured Data
$webaddress = 'http://www.<yourdomain>.com/files/'; //-- Full URL to files folder
$current_dir = 'files';//-- Directory to read
$page_title = '.::Directory Listing::.'; //-- Title of HTML document

//-- Display file as a link
//-- Change the value to '1' if you want the file to be displayed as a link.
//-- Change the value to '0' if you want the file to NOT be displayed as a link.
$asURL = '1';
//-- End User Configured Data
//-- You shouldn't have to touch anything below this line. Unless you want to format the HTML.
?>
<html>
<head>
<title><?php echo $page_title ?></title>
</head>
<body>
<table width='60%' align='center'>
<tr>
<td>Current directory is <b><?php echo $current_dir ?></b></td>
</tr>
<tr>
<td>Directory contains the following files...</td>
</tr>
<tr>
<td>
<?php
//-- Read the directory and display the results.

$dir = opendir($current_dir);
$fileAr = array();

while($file = (readdir($dir))){
if(is_file("$current_dir/$file")){
$fileAr[] = $file;
}
}
sort($fileAr);
reset($fileAr);
for($i=0;$i<count($fileAr);$i++){
if($asURL=='1'){
print("<a href=\"".$webaddress.$current_dir."/".$fileAr[$i]."\">".$webaddress.$fileAr[$i]."</a><br>");
}
if($asURL=='0'){
print($webaddress.$fileAr[$i]."<br>");
}
}

closedir($dir);
?>
</td>
</tr>
</table>
<hr width='60%'>
<br>
</body>
</html>




/Dan
<EDIT>
Darn, I just saw that you asked for TP's solution to be sorted... Doh!
Never mind, you should be able to look at this to see what I did and use that in TP's code, holler otherwise.
</EDIT>


{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

[This message has been edited by DmS (edited 04-01-2003).]

[This message has been edited by DmS (edited 04-01-2003).]

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 04-01-2003 13:42

good stuff. Now if I could just find mr.maX's PHP sig rotation script . . .

Later,

C:\


~Binary is best~

Suho1004
Maniac (V) Inmate

From: Seoul, Korea
Insane since: Apr 2002

posted posted 04-01-2003 23:46

http://www.ozoneasylum.com/Forum12/HTML/000318.html

[Edit: Although, after reading your post again, I realize that you said "PHP." I wasn't aware that he had a PHP rotation script...]

[This message has been edited by Suho1004 (edited 04-02-2003).]

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 04-02-2003 14:00

thanks for that though Suho. I was just going to incorporate both scripts. That way when I upload another image it will just scan the folder and then add it to the array for the sig rotation.

I am still working on that one

Later,

C:\


~Binary is best~

« BackwardsOnwards »

Show Forum Drop Down Menu