Jump to content

scanning directory help


jbwebdesign

Recommended Posts

I need help with a script that I am working on......

 

I want have it working properly to scan the directory but I want it to only display the .php files inside my directory....

 

can anyone help me out with this???

 

thanks

 

here is the script that I am using......

 

 

<?php

 

$dir = "../FORMfields/forms/generated/"; //You could add a $_GET to change the directory

 

$files = scandir($dir);

 

foreach($files as $key => $value){

 

echo '';

 

echo $value;

 

echo '

 

';

 

echo '';//You could add an icon in here maybe, a link to the file/directory, or a link to list files in that directory

 

}

 

?>

Edited by jbwebdesign
Link to comment
Share on other sites

I GOT THE CODE TO WORK KIND OF...... HERE IS MY CODE BUT NOW ITS SCANNING THE WRONG DIRECTORY.....

 

IT ONLY SCANS THE DIRECTORY THAT THE PHP FILE IS IN AND NOT THE ONE THAT ITS POINTING TO......

 

CAN SOMEONE PLEASE HELP ME???

 

THANKS

 

 

<?php

 

$dir = '../FORMfields/forms/generated/'; //You could add a $_GET to change the directory

 

$files = scandir($dir);

 

foreach(glob("*.php") as $files => $value){

 

echo '';

 

echo $value;

 

echo '

 

';

 

echo '';//You could add an icon in here maybe, a link to the file/directory, or a link to list files in that directory

 

}

?>

Link to comment
Share on other sites

$dir = './';    // change to suit your location needs
chdir($dir);    // Move to the directory named above
$filesg = glob('*.php');  // glob (make a list of) all (*) the php files found in the directory
if(empty($filesg)){
   echo 'no php files found...die
';
   die();      // die if no php files found
   }
else {
   foreach ($filesg as $file) {   // echo out the list of files with target name and title
   echo '';
   echo $file;
   echo '
';
   }
}
?>

Works for me.

 

I kept your Target in there, but please re-think using it to open new windows. Also added the tooltip title.

Edited by jlhaslip
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...