Advertisement
GWibisono

move_upload

Oct 6th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2. include "../config/koneksi.php";
  3. extract($_POST);
  4.     $newDate = date("Y-m-d", strtotime($_POST['tanggal']));
  5.     $list = array("jpg", "png","jpeg","gif");
  6.     $nama_file=$_FILES['datafile']['name'];
  7.     $pecah = explode(".", $nama_file);
  8.     $ekstensi = $pecah[1];
  9.     $ukuran=$_FILES['datafile']['size'];
  10.     $uploaddir='../links/';
  11.    
  12.     $alamatfile=$uploaddir.$nama_file;
  13.     $sql=mysql_query("SELECT * FROM  `tabel_link` WHERE id_link") or die('Error, query failed. ' . mysql_error());
  14.     $ada=mysql_fetch_array($sql);
  15.     $gambar=$ada['gambar'];
  16.     $imageInformation = getimagesize($_FILES['datafile']['tmp_name']);
  17.     $imageWidth = $imageInformation[0]; //Contains the Width of the Image
  18.     $imageHeight = $imageInformation[1]; //Contains the Height of the Image
  19.     $width=380;
  20.     $height=265;
  21. if (($imageWidth != $width) && ($imageHeight!=$height))
  22. {
  23.     echo "<script>
  24.                     alert ('Perhatikan ukuran');
  25.                     window.location='tambah_artikel.php';
  26.                     </script>";
  27.  
  28. }
  29.  
  30. //di bagian ini kok gak runing ya bang
  31.     if ($nama_file==$gambar)
  32.     {
  33.         echo "<script>
  34.                         alert ('Nama file sama, harap ganti');
  35.                     window.location='tambah_links.php';
  36.                         </script>";
  37.         die();
  38.  
  39.     }else{
  40.    
  41.         if (in_array($ekstensi, $list))
  42.         {
  43.             {if (move_uploaded_file($_FILES['datafile']['tmp_name'],$alamatfile)){       
  44.                 $sql1=mysql_query("INSERT INTO `cms`.`tabel_link` (`id_link`, `judul`, `tgl`, `gambar`,
  45.         `link`, `artikel`, `status`)
  46.         VALUES (NULL, '$judul', '$newDate', '$nama_file', '$link', '$artikel', '$stat')");                     
  47.                 if ($sql1){
  48.                  echo "<script>
  49.                     alert('upload OK');
  50.                     window.location='master_links.php';
  51.                  </script>";
  52.                 }else{
  53.                     die(mysql_error()."<br/>$sql");
  54.                
  55.                 }
  56.                                    
  57.                                        
  58.             }else{
  59.                 die('tidak bisa move file');
  60.            
  61.             }
  62.             }
  63.         }else{
  64.             echo "<script>
  65.                         alert ('Format harus jpg atau png');
  66.                         window.location='tambah_links.php';
  67.                         </script>";
  68.         }
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement