FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Directory lister





Relentless
Hi, I have a certain part on my site for uploading music, pictures & work. So I got a PHP directory listing thingie so that when I upload my work to the folder I can the open the work else where without loggin in & out of my Control Pannel.

But I have a problem.

It lists the files ok but is there away for the links to open in a new window (target="_blank" doesn't work)

here is the PHP script.

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 = "/Path/folder/here";

// 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 "&bull;<a href=\"$file\">$file</a><br>";
}

// Close
closedir($dir_handle);

?>


I noticed this
Code:
<a href=\"$file\">$file</a>
but if you add target="_blank" you get this error
Quote:
Un expexted VARIBLE on line 14


And if you add target=\"_blank" you get this error
Quote:
Un expexted VARIBLE "<" on line 14


please can sombody help.
The reason for the new window is because I am using this in a IFRAME so I am unable to got back after selecting an IMG ( I know you can press the backspace key but i am no the only user of this area and the others are not aware of the backspace)

Dan...
kv
Try this

Code:

echo "<a href='$file' target='_blank'>$file</a><br>";


You can also use javascript to open the link in new window. Here is an example.

http://www.yourhtmlsource.com/javascript/popupwindows.html
Relentless
Hi chears it worked..

but then i tried to use java script to use a pop up window function. the links don't work...

here is my PHP code

Code:
<?/

$path = "/home/magicdan/public_html/danielle/login/passed/Files/pictures/Upload/";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
echo "&bull;<a href='#' onClick='MM_openBrWindow('$file','Pictures','width=550,height=450,resizable=yes')'>$file</a><br>";
}

closedir($dir_handle);

?>



And here is the Java script

Code:
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


Please help

Thanks

Dan
kv
Try this

Code:

<?

   $path = "/home/magicdan/public_html/danielle/login/passed/Files/pictures/Upload/";
   $dir_handle = @opendir($path) or die("Unable to open $path");

   while ($file = readdir($dir_handle))
   {
      if($file == "." || $file == ".." || $file == "index.php" )
         continue;

      echo "<a href='#' onClick=\"MM_openBrWindow('$file','Pictures','width=550,height=450,resizable=yes')\" >$file</a><br>";
   }

   closedir($dir_handle);

?>


You have to be careful when placing quotes inside quotes.
Related topics
COFREE de Software
req: PHP to list files in directory, and link to them
PHP: Directory listing code
Full directory path
Add a directory?
New Directory Colors!
password protecting a directory
Temporary directory of web sites hosted by frih
What's up with the Frihost website directory?
How to use only one directory for image files ?
New Hosting Directory Forum
[PHP doubt]Knowing the directory location of PHP file
removing a directory completely..
Online directory
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.