Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. <?php
  2. error_reporting(-1);
  3.     if($_GET['task'] == "edit_photos")
  4.     {
  5.         if($_GET['do'] == "delete" && $_GET['id'] != "")
  6.         {
  7.             $id = intval($_GET['id']);
  8.             $result = mysql_query("DELETE FROM `photos` WHERE `id` = ".$id);
  9.             if(!$result)
  10.             {
  11.                 echo mysql_error();
  12.             }
  13.             else
  14.             {
  15.                 $a = unlink('../gallery/'.$id.'.jpg');
  16.                 $b = unlink('../gallery/'.$id.'_thub.jpg');
  17.                 if($a == true && $b == true)
  18.                 {
  19.                     echo "<span style='color:red;'>Photo deleted!</span>";
  20.                 }
  21.                 else
  22.                 {
  23.                     echo "<span style='color:red;'>Deletetion failed.!</span>";
  24.                 }
  25.                
  26.             }
  27.         }
  28.         else if($_GET['do'] == "update")
  29.         {
  30.             if($_POST['select'] != "")
  31.             {
  32.  
  33.                 foreach($_POST['select'] as $key => $value)
  34.                 {
  35.                     $id = $value;
  36.                     $title = mysql_real_escape_string($_POST['title_'.$id]);
  37.                     if($_FILES['photo_'.$id]['name'] != "")
  38.                     {
  39.                         if(unlink('../gallery/'.$id.'.jpg') == true)
  40.                         {
  41.                             $target_path = "../gallery/";
  42.                             $target_path = $target_path . basename( $_FILES['photo_'.$id]['name']);
  43.                             $upload = move_uploaded_file($_FILES['photo_'.$id]['tmp_name'], $target_path);
  44.                             if($upload == true)
  45.                             {
  46.                                 rename($target_path,"../gallery/".$id.".".end(explode('.', $_FILES['photo_'.$id]['name'])));
  47.                             }
  48.                         }
  49.                         else
  50.                         {
  51.                             echo "Failed to delete file";
  52.                         }
  53.                     }
  54.                     if($_FILES['thub_'.$id]['name'] != "")
  55.                     {
  56.                         $del2 = unlink('../gallery/'.$id.'_thub.jpg');
  57.                         if($de2 == true)
  58.                         {
  59.                             $target_path = "../gallery/";
  60.                             $target_path = $target_path . basename( $_FILES['thub_'.$id]['name']);
  61.                             $upload = move_uploaded_file($_FILES['thub_'.$id]['tmp_name'], $target_path);
  62.                             if($upload == true)
  63.                             {
  64.                                 rename($target_path2,"../gallery/".$id."_thub.".end(explode('.', $_FILES['thub_'.$id]['name'])));
  65.                             }
  66.                         }
  67.                         else
  68.                         {
  69.                             echo "Failed to delete file";
  70.                         }
  71.                     }
  72.                     $result = mysql_query("UPDATE `photos` SET `title` = '".$title."' WHERE `id` = ".$id);
  73.                 }
  74.             }
  75.         }
  76.     }
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement