Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with deleting files

    Hello,

    Im running into a problem, I have a single page login that displays the contents of a directory....



    Code:
    
    <hmtl>
    <head>
    
    
    	  <script LANGUAGE="JavaScript">
    <!--
    
    function confirmSubmit()
    {
    var agree=confirm("This will delete this File Permanently. Do you want to continue?");
    if (agree)
    	return true ;
    else
    	return false ;
    }
    // -->
    </script>
    </head>
    <body>
    <?php
    
    
    
    $username = "xxxxxxx";
    $password = "xxxxxxx";
    
    if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {
    
    ?>
    
    <center>
    
    <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">  
    <h1>Login <br> Holidays Get Published</h1><br>  
    <p><label for="txtUsername">Username:</label>    <br />
    <input type="text" title="Enter your Username" name="txtUsername" /></p>    
    <p><label for="txtpassword">Password:</label>    <br /><input type="password" title="Enter your password" name="txtPassword" /></p>
    <p><input type="submit" name="Submit" value="Login" class="buttons"/><br><br></p></form>
    </center>
    <?php 
    
    }
    
    else {
    
    
    ?>
    
    <? 
    
    $dir = 'xxxxx/xxxxx/xxxxxx/'; 
    $filecount = 0; 
    $d = dir($dir); 
    while ($f = $d->read()) { 
    if(($f!= ".") && ($f!= "..")) { 
    if(!is_dir($f)) $filecount++; 
    } 
    } 
    echo 'there are currently ',$filecount,' files <br><br>';
    
    
    
    
    
     $rep = "xxxxxxxx/xxxxxx/xxxx/";
    $dir = opendir($rep); 
    
    function dd($date) {
       return date("m/d/Y H:i:s",$date);
    }
    
    while ($f = readdir($dir)) {
       if(is_file($rep.$f)) {
       		echo "<div class='box'>";
          echo "<li>Name: $f";
    	  echo "<li><b><a href='xxxxxxxx/$f'>Download</a></b>&nbsp;&nbsp;&nbsp;<font color=red>(Right-Click, Save As...) </font>";
    	  echo "<li><b><a href='deletefiles.php?file=holidayuploads/$f&page=getcontent_holidays.php' onClick='return confirmSubmit()'>Delete</a></b>";
          echo "<li>Size: ".filesize($rep.$f)." bytes";
          echo "<li>Creation: ".dd(filectime($rep.$f));
          echo "<li>Modification: ".dd(filemtime($rep.$f));
    	  echo "<li>Thumb:<br><img src='holidayuploads/$f' width='150px'>";
    	  echo "</div>";
          echo "<br><br>";
       }
    }closedir($dir); ?>
    
    
    
    <?php
    
    
    }
    
    
    ?> 
    </body>
    </html>
    Now the problem is when i click delete is goes to a page called deletefiles.php where i have

    Code:
    <?php
    #!/usr/bin/php
    
    $do = unlink("$file");
    if($do=="1"){
    	echo "The file was deleted successfully. <meta http-equiv='refresh' content='2;url=$page'>";
    } else { echo "There was an error trying to delete the file."; }
    
    
    ?>
    then redirects back to the main page, this is where i have a problem, everytime i do it asked me to log in agian, is there a way around this?

    Thanks

    Ryan

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, you could use cookie or session to track whether user is valid. For example in the main php file that with login page you could add following code
    Code:
    if ($_POST['txtUsername'] == $username && $_POST['txtPassword'] == $password)
       {
         setcookie("valid_user",$username,time()+3600);
         ?>
         document.location.href = "path to main php file";
         <?
       }  
    if (!isset($_COOKIE['valid_user'])) {
        //show login screen
    }
    else {
        //display category content
    }
    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org


  •  

    Posting Permissions

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