browse files in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

browse files in php

Post by potato »

Hey,

i have a page where i can create new files with, it works when i just type the adress from root to write to.
But what i want to do is find some kind os class or something where i can browse the server and give the url with a form.
A kind like the browse files to upload to the server, but whit the server directories.
I hope you understand what i'm trying to explain.
Somebody knows a good or many used system like that?

Greetings and a cold beer!
tom
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Sorry, I have no clue what you are talking about. Maybe glob() ?
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post by kingconnections »

ok so I hope this helps, but to navigate directory structure you have to do a couple of things:

like set current working directory, then use opendir to open it, and readdir to read it and do whatever.


I wrote this a few days ago to traverse a section of folders in a given path. So other people on here helped me as well. But you will get the picture hopefully.


Code: Select all

<? 
set_time_limit(0);

$path=getcwd();
$path.="\\CTM";
chdir($path);

$default_dir = ".\\CTM\\";
function traverse_dir($dir) {
   echo "Traversing $dir....<BR>";
   chdir($dir);
   if(!($dp = opendir($dir))) die("Can't open $dir.");

   while($file = readdir($dp)) {
      if(is_dir($file)) {
         if($file != '.' && $file != '..') {
            echo "\\$file<BR>";
            traverse_dir("$dir\\$file");
            chdir($dir);
         }
      }
      else echo "$file<BR>";
      
   }
   
   closedir($dp);
}

traverse_dir($path);


?>
output:


Code: Select all

Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM....
\BACKUP
Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM\BACKUP....
\UNIX
Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM\BACKUP\UNIX....
PDISBK0002
PDISBK0003
PDISBK0004
PDISBK0012
\BWDEV
Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM\BWDEV....
\BW
Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM\BWDEV\BW....
\ESSBASE
Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM\BWDEV\BW\ESSBASE....
\BWPRD
Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM\BWPRD....
\BW
Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM\BWPRD\BW....
\ESSBASE
Traversing d:\wwwroot\Policies\Jobscheduling\scripts\jobdoc\CTM\BWPRD\BW\ESSBASE....
PBWEB0004
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

After reading that many, many times. I believe I understand your question.

You want to browse the directories on the server and upload files to them without having to type it in manually, correct?

That is easy for the most part. You start with the root directory and have the page list all the folders. Then let's pretend that you clicked on the name of a folder, the page changes the working directory and you see the contents of the directory that you previously clicked. Throw an upload button in there somewhere and you are good to go.
Post Reply