<?php // Create connection $servername='localhost'; $username='root'; $password=''; $database='test'; // $con= mysqli_connect($servername,$username,$password,$database) or die('connection failed'); $con= mysqli_connect($servername,$username,$password,$database) or die('connection failed'); //delete if(@$_GET['del']!=''){ $delquery= " DELETE FROM file_upload WHERE file_id='".@$_GET['del']."'"; if ($RunDelQ = mysqli_query($con,$delquery)){ echo '<div class="alert alert-info"> delete successfully</div>';}} //insert file if(isset($_POST['file_id'])){ // if(isset($_POST['submit'])){ if($_POST['file_id']==''){ if(isset($_FILES['upload_file'])){ // print_r($_FILES); // $errors = array(); $filename= $_FILES["upload_file"] ["name"]; $tempname= $_FILES["upload_file"] ["tmp_name"]; $folder = "upload/" .$filename; move_uploaded_file($tempname, $folder); $InsQuery="INSERT INTO file_upload (upload_img) VALUES('".$folder."')"; // echo $InsQuery;die(); // for insert databas exkute $RunQuery = mysqli_query($con,$InsQuery); if($RunQuery){ echo '<div class="alert alert-info"> upload successfully</div>';}}}} //5 update if(@$_POST['file_id']!=""){ // echo $_POST['file_id']; die(); $folder = @$_POST['upload_oldfile']; if(@$_FILES["upload_file"] ["name"]!=""){ $filename= $_FILES["upload_file"] ["name"]; $tempname= $_FILES["upload_file"] ["tmp_name"]; $folder = "upload/" .$filename; move_uploaded_file($tempname, $folder); } $UpdateQuery= "UPDATE file_upload SET upload_img='".$folder."' WHERE file_id='".@$_GET['uid']."'"; // echo $UpdateQuery; die(); if($runUp=mysqli_query($con,$UpdateQuery)){ echo '<div class="alert alert-success"> updated successfully</div>';}} //fetch data for edition if(@$_GET['uid']!=""){ // echo $_GET['uid']; die(); $editQuery="SELECT *FROM file_upload WHERE file_id='".@$_GET['uid']."' "; $runEditQ= mysqli_query($con,$editQuery); $editData = mysqli_fetch_assoc($runEditQ); }?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>upload img</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <link rel="stylesheet" href="style.css" type="text/css"> <link rel="stylesheet" href="css/bootstrap-grid.min.css" type="text/css"> </head> <body> <form class="text-warning " action="" method="POST" enctype="multipart/form-data"> <div class="form-group"> <input type="hidden" class="form-control-file" name="file_id" value="<?php echo @$_GET['uid'] ?>"> <label for="exampleFormControlFile1 text-warning display: inline-block " ><h2>Example file input</h2></label> <input type="file" class="form-control-file" name="upload_file"> <input type="hidden" class="form-control-file" name="upload_oldfile" value="<?php echo $editData['upload_img'] ?>"> <?php if(@$editData['upload_img']!='') echo '<img src=" '.@$editData["upload_img"] .'" width="50"/> <a href=" '.@$editData["upload_img"].'" target="_blank">old uploaded</a>'?></div> <div class="form-group"> <!-- <button type="submit" name="submit" value="Submit">Submit</button> --> <input type="submit" name="submit" value="Submit"> </div> </form> <h2 class="text-center"> insert file into database</h2> <table style="width: 100%;" border="1"> <thead> <tr><th>SR</th> <th>IMG</th> <th>Operation</th></tr> </thead> <?php $abc=1; // slect form data base $slectdata= "SELECT *FROM file_upload"; $Runselect= mysqli_query($con,$slectdata); if(mysqli_fetch_row($Runselect)>0){; // echo 'Row found'; foreach($Runselect as $key=> $value) {?> <tbody> <tr> <td align="center"><?php echo $abc++ ?></td> <td align="center"> <img src="<?php echo $value['upload_img'] ?>" height="80px" width="80px"> <?php echo '<a href=" '.@$value["upload_img"].'" target="_blank"style="padding:10px;color:white; font-size:larger; background:grey" >VIEW</a>'?></td> <td align="center"><a href="index.php?uid=<?php echo $value['file_id'] ?>" style="padding:10px;color:white; font-size:larger; background:green">EDIT</a> <a href="index.php?del=<?php echo $value['file_id']?>" style="background:red;color:white;padding:10px;font-size:larger">DELETE</a> </td></tr><?php } }else{echo '<tr><td colspan="10"> ROW NOT FOUND</td></tr>'; }?></tr> </tbody </table> </body> </html>
September-04-2024 09:18:37
August-11-2024 11:31:12
August-02-2024 23:22:25
May-12-2024 02:44:34
May-10-2024 20:14:30