Popup menu to delete file from folder

php India
  • 15 years ago
    hi,

    Description
    I am displaying the files from a folder. By right clicking i should get a pop up menu if i select Delete option
    i should be able to delete the selected file.I wrote java script to get popup menu.with delete option.

    when i will keep my cursor on particular link of a file.when i will right click on that how i can get that file name
    so that i can able to delete that file.

    Code used:

    <script type="text/javascript">
    var ie  = document.all
    var ns6 = document.getElementById&&!document.all
    var isMenu  = false ;
    var menuSelObj = null ;
    var overpopupmenu = false;
    function mouseSelect(e)
    {
     var obj = ns6 ? e.target.parentNode : event.srcElement.parentElement;
     if( isMenu )
     {
       if( overpopupmenu == false )
       {
         isMenu = false ;
         overpopupmenu = false;
         document.getElementById('menudiv').style.display = "none" ;
         return true ;
       }
       return true ;
     }
     return false;
    }
    // POP UP MENU
    function  ItemSelMenu(e)
    {
     var obj = ns6 ? e.target.parentNode : event.srcElement.parentElement;
         menuSelObj = obj ;
     if (ns6)
     {
       document.getElementById('menudiv').style.left = e.clientX+document.body.scrollLeft;
       document.getElementById('menudiv').style.top = e.clientY+document.body.scrollTop;
     } else
     {
       document.getElementById('menudiv').style.pixelLeft = event.clientX+document.body.scrollLeft;
       document.getElementById('menudiv').style.pixelTop = event.clientY+document.body.scrollTop;
     }
     document.getElementById('menudiv').style.display = "";
     document.getElementById('Delete').style.backgroundColor='#FFFFFF';

     isMenu = true;
     return false ;
    }
    document.onmousedown  = mouseSelect;
    document.oncontextmenu  = ItemSelMenu;
    //-->
    </script>
    </HEAD>

    <BODY>
    <?php

    $main = ".";
    $dir = opendir($main);                                         // unbutton it
    $i = 1;                                                        // for column count

    while($filename = readdir($dir))
    {
    {
     if (filetype($filename)=="file")
      {

       $filename1=substr($filename, -3, 3);
       if( $filename1==pdf || $filename1==PDF)
       {

        if ($i <= '1')
               {
                   $i = $i + '1';
                   echo '<td align="left" width="115" height="100">';  ?>
                   <p><a href="<?=$filename;?>" target="topFrame" onClick="parent.passText('<?=$filename;?>');"><?=$filename;?></a></p>
                  <? echo'</td>';
                   ?>

    <!--------------------- BEGIN POPUP MENU -------------------------->
    <div id="menudiv" style="position:absolute; display:none; top:0px; left:0px;z-index:10000;" onmouseover="javascriptverpopupmenu=true;" onmouseout="javascriptverpopupmenu=false;">
    <table width=82 cellspacing=1 cellpadding=0 bgcolor=lightgray>
     <tr><td>
       <table width=80 cellspacing=0 cellpadding=0>
         <tr>
           <td id="Delete" bgcolor="#FFFFFF" width="80" height="16" onMouseOver="this.style.backgroundColor='#EFEFEF'" onMouseOut="this.style.backgroundColor='#FFFFFF'">
           <a href="<?=$filename;?>">Delete</a></td>


     </tr>
     </table>
     </td></tr>
    </table>
    </div>
    <!--------------------- END POPUP MENU -------------------------->

     <?
               }
        else
               {
                   $i = '1';
                   echo '</tr>
                   <tr>';
                   $i = $i + '1';
                   echo '<td align="left" width="115" height="100">';  ?>
                  <p><a href="<?=$filename;?>" target="topFrame" onClick="parent.passText('<?=$filename;?>');"><?=$filename;?></a></p>
                  <? echo'</td>';
                ?>

    <!--------------------- BEGIN POPUP MENU -------------------------->
    <div id="menudiv" style="position:absolute; display:none; top:0px; left:0px;z-index:10000;" onmouseover="javascriptverpopupmenu=true;" onmouseout="javascriptverpopupmenu=false;">
    <table width=82 cellspacing=1 cellpadding=0 bgcolor=lightgray>
     <tr><td>
       <table width=80 cellspacing=0 cellpadding=0>
         <tr>
           <td id="Delete" bgcolor="#FFFFFF" width="80" height="16" onMouseOver="this.style.backgroundColor='#EFEFEF'" onMouseOut="this.style.backgroundColor='#FFFFFF'">
           <a href="<?=$filename;?>">Delete</a></td>


     </tr>
     </table>
     </td></tr>
    </table>
    </div>
    <!--------------------- END POPUP MENU -------------------------->

     <?
               }
         }
       }
    }
    }

    closedir($dir);                                             // button it up

    echo '</tr></table></center>';
    exit;
    ?>
    </body>

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”