There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen blue screen of death boot bsod computer connection crash css dell display driver drivers email error explorer firefox firefox 3 hard drive internet internet explorer itunes laptop lcd malware monitor network networking outlook outlook 2003 outlook express printer problem problems ram router security slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Reading file names with HTML Script


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
TinkeringTom's Avatar
Computer Specs
Junior Member with 3 posts.
 
Join Date: Sep 2007
Experience: Beginner
08-Oct-2007, 11:55 AM #1
Reading file names with HTML Script
Rather than changing my code to display JPG's etc, everytime I add or delete one, I would like to be able to read the file names in a directory and determine which files should be displayed. Is there a way to do this? Any help will be greatly appreciated.
haswalt's Avatar
Computer Specs
Senior Member with 416 posts.
 
Join Date: Nov 2004
Location: South Coast, UK
Experience: Advanced
08-Oct-2007, 12:45 PM #2
well with php you could:

1) get a list of all files in the folder
2) get all the ones that are jpegs, gifs, etc
3) display them on the page in a format you like

Like this:

PHP Code:
$path "images/"

// Open the folder 
$dir_handle = @opendir($path) or die("Unable to open $path"); 

// Loop through the files 
while ($file readdir($dir_handle)) { 

if(
$file == "." || $file == ".."
continue; 
checkImage($file); 



// Close 
closedir($dir_handle); 
That will list all files in the folder except "." and ".." then run a function on each file as it loops to determine whether it is an image or not:

PHP Code:
function checkImage($img_file) {
     if ( 
preg_match("/(\.gif|\.png|\.jpg)$/"$img_file) ) { 
          echo 
'<img src="images/'.$img_file.'" />';
      }

I have't test this code, i jsut guessed but i can do a complete script for you on this, depends really on your host as im only really an knowledgable in PHP.

Thanks

Harry
__________________
LQD Internet Limited
We've just got better! With the launch of our new site we have SLASHED our prices and upped the offering. Check it out!

10% Discount for ALL Tech Support Guy Members
Simply use the promo code of "T3CHGUY" when ordering to recieve your 10% discount on all shared and reseller hosting packages.
TinkeringTom's Avatar
Computer Specs
Junior Member with 3 posts.
 
Join Date: Sep 2007
Experience: Beginner
08-Oct-2007, 02:35 PM #3
I'm not familiar with PHP, only Script, but I may have to get familiar it. Does this work just like script?
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,197 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
08-Oct-2007, 08:29 PM #4
Quote:
Originally Posted by TinkeringTom
I'm not familiar with PHP, only Script, but I may have to get familiar it. Does this work just like script?
What do you mean by "script"?

HTML isn't a scripting language, it's a markup language (referring to thread title).

PHP is a scripting language, so is JavaScript.

JavaScript is client-side, and PHP is server-side.
TinkeringTom's Avatar
Computer Specs
Junior Member with 3 posts.
 
Join Date: Sep 2007
Experience: Beginner
08-Oct-2007, 09:17 PM #5
Sorry, I mean JavaScript. I haven't had time to use the example yet, but I'm guessing that it works just like JavaScript.

Thnx
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,197 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
08-Oct-2007, 09:25 PM #6
Oh ok, then yeah it's kinda similar. They both use /* and */ for comments.

With PHP you have to wrap all code between <?php and ?> tags. And the page has to have a ".php" file extension.

How PHP differs from javascript: A variable in PHP starts with $ like $hello, whereas in JS a variable starts with "var" as in var hello.
__________________
-----------------------------
| 404: Name Not Found |
-----------------------------
PLEASE NOTE: If I happen to help you in a post, or just simply reply to it, doesn't mean I want to be bombarded with PMs. I answer all questions in posts, not in PMs. Thank you, and have a good day.

<?php $h = 'Hello '; $w = 'World'; echo $h.$w; ?>

My Favorite Editors:
Windows: Crimson Editor
Mac: Taco HTML Edit
Linux: gPHPEdit
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:37 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.