SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    opendir problem.

    PHP Code:
    <?php 
    if (!isset($_GET['file']) && $_GET['confirm'] != "yes"){ 
        echo 
    "Click on link to delete files"
    if (
    $handle opendir('/danielle')) { 
       echo 
    "Directory handle: $handle\n"
       echo 
    "Files:\n"


       while (
    false !== ($file readdir($handle))) { 
    ?> 

    <a href="delete.php?file=<?php echo $_GET['file']; ?>&confirm=yes" onclick="return confirm('Are you sure you want to delete the file?')"><?php echo $file?></a><br> 
        <? 
       


       
    closedir($handle); 

    }else{ 
    if (
    file_exists($exfile)) { 
        
    unlink($_GET['file']);  
        }else{ 
            echo 
    "File doesn't exist"
            } 
            } 
    ?>
    It isn't listing the files. I need it open the dir domain.com/danielle

    ?

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    while ($file readdir($handle)) { 
    cheers

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm also getting the
    Code:
    Warning: opendir(/danielle): failed to open dir: No such file or directory in /***.com/www/danielle/delete.php on line 4
    ?

    The directory DOES exist.

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have to give it the full path found on the server, such as
    Code:
    /path/to/danielle/
    @ reminder:
    check the documentation for opendir() at www.php.net to find out why his way is right and your way is not recommended

  5. #5
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    P.S. - you might want to throw this if statement in before you start with your output, just to make sure that everything shown is actually deleteable:
    PHP Code:
    if ($file!='.' && $file!='..' && !is_dir($file)) {
         
    //output the link to delete here


  6. #6
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it worked everytime for me!

  7. #7
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by reminder
    it worked everytime for me!
    yes, your way will work, but it is not the recommended way of reading a directory

    just putting this here so that those new to php won't get confused or misled

  8. #8
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now it's listing the directory, but now when I click, I'm getting the file doesn't exist message.

  9. #9
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it, thanks guys.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •