logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > HTML and CSS
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 08-08-2008, 08:52 PM   #1
lorne17
 
Join Date: Jun 2008
Posts: 15
Default Show folder files and content with automatic list??

Hello there,

I am trying to get a page where our clients can login and view the password protected folder (the one they login to) and download files to their own machines.

I have successfully completed this task. BUT, I don't like the way the Folder index page looks. Is there a way to create an index page that will automatically list all files and content in the folder the client just logged into?

Also once logged in, can I get a File Upload form so the client can upload their own files to that folder?

Take a look at the attached photos. What I'm getting is the typical white background, blue text and file list/info. But I don't want that. I want it to match our site and look good. Like the second picture that shows the "Client Login" page. A similar list like that where clients can login and download files. Can anyone help? I am using Dreamweaver cs3.

Thanks,

Lorne
Attached Images
File Type: jpg Picture-2.jpg (14.0 KB, 10 views)
File Type: jpg Picture-1.jpg (11.4 KB, 11 views)
lorne17 is offline   Reply With Quote
Old 08-09-2008, 12:21 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,202
Default

yes with php. i gave a snippet a while ago here but lost it. i havent used this but try this. drop it in a class and you can style as you want
PHP Code:
<?  

/**  
* Change the path to your folder.  
*  
* This must be the full path from the root of your  
* web space. If you're not sure what it is, ask your host.  
*  
* Name this file index.php and place in the directory.  
*/  

// Define the full path to your folder from root  
$path "full path to folder";  

// 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 == ".." || $file == "index.php" )  

continue;  
echo 
"<a href=\"$file\">$file</a><br>&gt;";  

}  

// Close  
closedir($dir_handle);  

?>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 08-11-2008, 10:42 PM   #3
lorne17
 
Join Date: Jun 2008
Posts: 15
Default

I'm really new with PHP. Is there anything special I need to do to input this into my page? I inserted this code into my index.php page which is located in the folder that I want to list the contents. When I went to preview it, it said "Unable to open /www/htdocs/client login files/test/"

Why is this? I can't figure out what I'm doing wrong? Is it due to the spaces in the "client login files" for the folder name? I tried the 20% inbetween for spaces...but still no dice.

I found this coding from another forum, and this didn't work either. What am I missing? Thanks,

Lorne

PHP Code:
<?php 

function getDirectoryListing($dirname$sortorder "a"$show_subdirs 0$show_subdirfiles 0$exts ""$ext_save 1) { 
// This function will return an array with filenames based on the criteria you can set in the variables 
// @sortorder : a for ascending (the standard) or d for descending (you can use the "r" for reverse as well, works the same) 
// @show_subdirs : 0 for NO, 1 for YES - meaning it will show the names of subdirectories if there are any 
// Logically subdirnames will not be checked for the required extentions 
// @show_subdirfiles : 0 for NO, 1 for YES - meaning it will show files from the subdirs 
// Files from subdirs will be prefixed with the subdir name and checked for the required extentions. 
// @exts can be either a string or an array, if not passed to the function, then the default will be a check for common image files 
// If exts is set to "all" then all extentions are allowed 
// @ext_save : 1 for YES, 0 for NO - meaning it will filter out system files or not (such as .htaccess) 

  
if (!$exts || empty($exts) || $exts == "") { 
       
$exts = array("jpg""gif""jpeg""png"); 
   } 
   if (
$handle opendir($dirname)) { 
       
$filelist = array(); 
       while (
false !== ($file readdir($handle))) { 

           
// Filter out higher directory references 
           
if ($file != "." && $file != "..") { 
               
// Only look at directories or files, filter out symbolic links 
               
if ( filetype ($dirname."/".$file) != "link") { 
                   
// If it's a file, check against valid extentions and add to the list 
                   
if ( filetype ($dirname."/".$file) == "file" ) {
                       if (
checkFileExtention($file$exts$ext_save)) { 
                                       
$filelist[] = $file
                       } 
                   } 
                   
// If it's a directory and either subdirs should be listed or files from subdirs add relevant names to the list 
                   
else if ( filetype ($dirname."/".$file) == "dir" && ($show_subdirs == || $show_subdirfiles == 1)) { 
                       if (
$show_subdirs == 1) { 
                           
$filelist[] = $file
                       } 
                       if (
$show_subdirfiles == 1) { 
                           
$subdirname $file
                           
$subdirfilelist getDirectoryListing($dirname."/".$subdirname."/"$sortorder$show_subdirs$show_subdirfiles$exts$ext_save); 
                           for (
$i $i count($subdirfilelist) ; $i++) { 
                               
$subdirfilelist[$i] = $subdirname."/".$subdirfilelist[$i]; 
                           } 
                           
$filelist array_merge($filelist$subdirfilelist); 
                       } 

                   } 

               } 
           } 
       } 
       
closedir($handle); 

       
// Sort the results 
       
if (count($filelist) > 1) { 
           
natcasesort($filelist); 
           if (
$sortorder == "d" || $sortorder == "r" ) { 
               
$filelist array_reverse($filelistTRUE); 
           } 
       } 
       return 
$filelist
   } 
   else { 
       return 
false
   } 


function 
checkFileExtention($filename$exts$ext_save 1) { 
   
$passed FALSE
   if (
$ext_save == 1) { 
       if (
preg_match("/^\./"$filename)) { 
           return 
$passed
       } 
   } 
   if (
$exts == "all") { 
                   
$passed TRUE
       return 
$passed
   } 
   if (
is_string($exts)) { 
       if (
eregi("\."$exts ."$"$filename)) { 
                       
$passed TRUE
           return 
$passed
       } 
   } else if (
is_array($exts)) { 
       foreach (
$exts as $theExt) { 
           if (
eregi("\."$theExt ."$"$filename)) { 
               
$passed TRUE
               return 
$passed
           } 
       } 
   } 
   return 
$passed

?>
lorne17 is offline   Reply With Quote
Old 08-12-2008, 01:20 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,202
Default

i have not tried it , as i said i lost my original snippet but i posted it here somewhere, it does work I know. ill try this one later
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 08-12-2008, 04:38 AM   #5
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,202
Default

k thats a function and you have to call it, however its not what you want i think
try this
Code:
<?php
 if ($handle = opendir('.')) {
   while (false !== ($file = readdir($handle)))
      {
          if ($file != "." && $file != "..")
	  {
          	$thelist .= '<a href="'.$file.'">'.$file.'</a>';
          }
       }
  closedir($handle);
  }
?>
<p>List of files:</p>
<p><?=$thelist?></p>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 08-12-2008, 04:44 AM   #6
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,202
Default

and if you changed
$thelist .= '<a href="'.$file.'">'.$file.'</a>;
to
$thelist .= '<a href="'.$file.'">'.$file.'</a>'.'<br>';
it will list files in a new line
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 08-12-2008, 05:34 AM   #7
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,202
Default

k getting into this now
playing with code example from w3 schools this lets you list files in a specific folder, in this case images so change to suit, with links to the files
Code:
<?php
//Open images directory
$dir = opendir("images");

//List files in images directory
while (($file = readdir($dir)) !== false)
  {
   if ($file != "." && $file != "..")
      {
  echo '<a href="'.$file.'">' . $file . '</a>'."<br />";
  }
  }
  closedir($dir);
?>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 08-13-2008, 05:53 PM   #8
lorne17
 
Join Date: Jun 2008
Posts: 15
Default

Ok what am I missing here...I tried your last post:

PHP Code:
<?php
//Open images directory
$dir opendir("test");

//List files in images directory
while (($file readdir($dir)) !== false)
  {
   if (
$file != "." && $file != "..")
      {
  echo 
'<a href="'.$file.'">' $file '</a>'."<br />";
  }
  }
  
closedir($dir);
?>
I changed the images folder to "test" because that's what my folder I want listed is called.

Am I missing something? The attached image shows what the page shows when the link to index.php was clicked.

Thanks for your help

Lorne
Attached Images
File Type: jpg Picture-1.jpg (16.5 KB, 8 views)
lorne17 is offline   Reply With Quote
Old 08-13-2008, 06:16 PM   #9
lorne17
 
Join Date: Jun 2008
Posts: 15
Default

Ok so I tried this code and it worked!!

PHP Code:
<?php
 
if ($handle opendir('.')) {
   while (
false !== ($file readdir($handle)))
      {
          if (
$file != "." && $file != "..")
      {
              
$thelist .= '<a href="'.$file.'">'.$file.'</a>'.'<br>';
          }
       }
  
closedir($handle);
  }
?>
<p style="font-weight: bold; font-size: 10pt">List of files:</p>
<p style="font-weight: bold; font-size: 10pt; color: #560D1C"><?=$thelist?></p>
The only thing now is, am I able to automatically hide specific files from the list?? I.E. .htaccess, index.php??

Just show all other files? Thanks

Lorne
lorne17 is offline   Reply With Quote
Old 08-13-2008, 06:43 PM   #10
lorne17
 
Join Date: Jun 2008
Posts: 15
Default

Sorry still playing with this.

So two things I'd like to do with this...
1. hide specific files
2. upload files to the same folder.

Regarding the upload files, i've been trying to play with it on W3Schools, but can't quite seem to get it to work. Any thoughts??

Thanks,

Lorne
lorne17 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:47 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com