Advertisement
GWibisono

upload ganti ke copy dan ganti logic

Feb 7th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $update=true;
  3. if ($act=='update'){
  4.     $lokasi_file = $_FILES['image']['tmp_name'];
  5.     $tipe_file = $_FILES['image']['type'];
  6.     $nama_file = $_FILES['image']['name'];
  7.     $acak = rand(1,99);
  8.     $nama_file_unik = $acak.$nama_file;
  9.  
  10.  
  11.     if (empty($lokasi_file)){
  12.         $update=mysql_query("UPDATE slide SET judul='$_POST[judul]',
  13.         detail='$_POST[kata]',
  14.         link='$_POST[link]'
  15.         WHERE kd_slide = '$_POST[kd_slide]'");
  16.     }
  17.     else{
  18.         if( UploadImage1($nama_file_unik)){
  19.             $update=mysql_query("UPDATE slide SET judul='$_POST[judul]',
  20.             detail='$_POST[kata]',
  21.             link='$_POST[link]',
  22.             image='$nama_file_unik'
  23.             WHERE kd_slide = '$_POST[kd_slide]'");
  24.         }
  25.         else{
  26.             $update=false;
  27.         }
  28.     }
  29.    
  30.    
  31. }else{
  32.     $update=false;
  33. }
  34.  
  35. if($update ===FALSE){
  36.         echo '
  37.         <div class="wrapper-page">
  38.         <div class="ex-page-content text-center">
  39.         <h2>Gagal Edit Data</h2>
  40.         <br>
  41.         <p class="text-muted">
  42.         Hubungi admin untuk perbaiki.
  43.         </p>
  44.         <br>
  45.         <a class="btn btn-default waves-effect waves-light" href="admin.php"> Return Home</a>
  46.  
  47.         </div>
  48.         </div>
  49.         ';
  50. }
  51. else{
  52.     header('location:admin.php?page=slide');exit();
  53. }
  54.  
  55.  
  56.  
  57. function UploadImage1($fupload_name){
  58.     //direktori gambar
  59.     $vdir_upload = "../images/slider/";
  60.     $vfile_upload = $vdir_upload . $fupload_name;
  61.  
  62.     //chmod("$vfile_upload", 0644);
  63.  
  64.     //Simpan gambar dalam ukuran sebenarnya
  65.     if(copy($_FILES["image"]["tmp_name"], $vfile_upload)){
  66.         //identitas file asli
  67.         $im_src = imagecreatefromjpeg($vfile_upload);
  68.         $src_width = imageSX($im_src);
  69.         $src_height = imageSY($im_src);
  70.  
  71.         //Simpan dalam versi small 1920 pixel
  72.         //Set ukuran gambar hasil perubahan
  73.         $dst_width = 1920;
  74.         $dst_height = ($dst_width/$src_width)*$src_height;
  75.  
  76.         //proses perubahan ukuran
  77.         $im = imagecreatetruecolor($dst_width,$dst_height);
  78.         imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
  79.  
  80.         //Simpan gambar
  81.         imagejpeg($im,$vdir_upload . "small_" . $fupload_name);
  82.  
  83.         //Hapus gambar di memori komputer
  84.         imagedestroy($im_src);
  85.         imagedestroy($im);
  86.    
  87.     }else{
  88.         return false;
  89.     }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement