Page 1 of 1

browse files in php

Posted: Thu Dec 28, 2006 1:49 pm
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

Posted: Thu Dec 28, 2006 2:03 pm
by Oren
Sorry, I have no clue what you are talking about. Maybe glob() ?

Posted: Thu Dec 28, 2006 2:16 pm
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

Posted: Thu Dec 28, 2006 2:18 pm
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.