lundi 8 mai 2017

unlink() imagesissue-using checkbox multiple images delete but issue on unlink() file from folder

i have a problem for unlink()function on php i have a used checkedbox for delete images or video uploded file multiple images or video delete sucessfully from database but not delete from local folder using unlink() no any error but when i select all checkbox and press delete then delete all files from database but only first file unlink


here my code

<?php  // for delete checked video php script 

include('config.php');

if(isset($_POST['delete']))
    {

    $checkedCandidates = 0;
    $id = implode(",", $_POST['deletecb']);

    $checkedCandidates = count($id);

                if ($checkedCandidates < 1) {

                     echo "<div id=\"errormsg\"> You need to check at least one video for delete. </div>";

                           echo "<script>setTimeout(\"location.href = 'video_upload.php';\",3000);</script>";  
                }
                else {

                    $result=mysqli_query($connection,"SELECT * FROM video_gallery where  id_vid IN($id) and users_name='$login_session'");

                        while ($row=mysqli_fetch_assoc($result))
                        {
                        $fname=$row[FILE_NAME]; 

                        $Path="data/58f60f2e09f07_jay/videos/$fname";
                            if (file_exists($Path)){
                                if (unlink($Path)) {   
                                    echo "success";
                                } else {
                                    echo "fail";    
                                }   
                            } else {
                                echo "file does not exist";
                            }
                        }
                    $query1=mysqli_query($connection,"delete from video_gallery where id_vid IN($id) and users_name='$login_session'");                         
                        if($query1)
                        {
                            echo "<div id=\"successmsg\"> delete successfully </div>";
                        }
                        else
                        {
                            echo "<div id=\"errormsg\"> failed operation!!</div>";
                        }  
                    }

    }


?>




Aucun commentaire:

Enregistrer un commentaire