Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,668 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,148 people online right now. Registration is fast and FREE... Join Now!




Files loading

 
Reply to this topicStart new topic

Files loading

k0b13r
post 14 Aug, 2007 - 05:26 PM
Post #1


D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 196



Thanked 1 times

Dream Kudos: 250
My Contributions


Hi. I wanted to load every file in specified directory to array ( via file(); ). How can I "jump" over all files without specifing their names ? Thanks for answer
User is offlineProfile CardPM

Go to the top of the page

snoj
post 14 Aug, 2007 - 05:36 PM
Post #2


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


file() doesn't work that way.

Come back when you know what you're doing.

[edit] my apologies for the above comment, it was uncalled for.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 14 Aug, 2007 - 05:40 PM
Post #3


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


Run a dir listing, get all the files, & load each of them inside of a for statement.

CODE

function read_dir($dir) {
   $dir_Array=array();
   $path = opendir($dir);
   while (false !== ($file = readdir($path))) {
        if(is_file($dir."/".$file)) $files[]=$file;
        else  $dirs[]=$dir."/".$file;
   }
   if($dirs) {
       natcasesort($dirs);
       foreach($dirs as $dir) {
           //echo $dir;
           read_dir($dir);
       }
   }
   if($files) {
     array_push($dir_Array,$files);
     $_i=0;
     natcasesort($files);
     foreach ($files as $file) {
       // load them here...
     }
  }
}

Soooomething similar to this. This code was pulled from one of my sites that pulls a dir listing.

Good luck!
User is offlineProfile CardPM

Go to the top of the page

k0b13r
post 14 Aug, 2007 - 05:42 PM
Post #4


D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 196



Thanked 1 times

Dream Kudos: 250
My Contributions


I can put file content into array via file, but I have to specify file name. I want to put contents of each file like this, but I want to script take file names by itself automatically, if You understand what I mean ... biggrin.gif Is it possible ?

Thanks no2pencil, I will take a look of this smile.gif

This post has been edited by k0b13r: 14 Aug, 2007 - 05:43 PM
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 14 Aug, 2007 - 05:51 PM
Post #5


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


QUOTE(k0b13r @ 14 Aug, 2007 - 06:42 PM) *

I can put file content into array via file, but I have to specify file name.

The code I supplied will run on ANY file in a directory, you do not have to referance each file. Simply say WHICH directory you want to load every file from.

QUOTE(k0b13r @ 14 Aug, 2007 - 06:42 PM) *

Thanks no2pencil, I will take a look of this smile.gif


Good luck.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:54AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month