Advertisement
GWibisono

autonumber

Mar 27th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if (isset($_POST['upload']))
  4. {
  5.     $name=$_FILES['file_video']['name'];
  6.     $type=$_FILES['file_video']['type'];
  7.     $size=$_FILES['file_video']['size'];
  8.     //replace tanda spasi pada nama file dengan _
  9.     $nama_file=str_replace(" ","_",$name);
  10.     $tmp_name=$_FILES['file_video']['tmp_name'];
  11.     $nama_folder="video/";
  12.     $id=auto_number();
  13.     $nama_file_baru=$nama_folder.basename($id);
  14.     //Filter jenis file video dan ukuran file
  15.     if ((($type == "video/mp4") || ($type == "video/3gpp")  || ($type == "video/x-flv")) && ($size < $_POST['MAX_FILE_SIZE']))
  16.     {
  17.         //cek jika nama dile sudah ada
  18.         if (file_exists($nama_file_baru))
  19.         {
  20.             $msg="Nama file $nama_file sudah ada!\n";
  21.         }
  22.         else
  23.         {  
  24.             //pindah file dari temporari ke alamat tujuan
  25.             if(move_uploaded_file($tmp_name,$nama_file_baru))
  26.             {
  27.                 $msg="File video $nama_file berhasil diupload";
  28.             }
  29.         }
  30.     }
  31.     else
  32.     {
  33.         $msg="Jenis file tidak sesuai atau ukuran file terlalu besar!";
  34.     }
  35.     echo "<p align=\"center\">$msg</p>";
  36. }
  37.  
  38. else
  39. {
  40. ?>
  41. <html>
  42. <head>
  43. <title>Upload Video dengan PHP</title>
  44. </head>
  45. <body>
  46. <div style="width:800px;margin:20px auto; text-align:center">
  47. <fieldset>
  48. <legend>Upload Video</legend>
  49. <form name="fvideo" enctype="multipart/form-data" method="POST" action="" style="padding:10px;">
  50. <input name="MAX_FILE_SIZE" value="50000000" type="hidden"/>
  51. <input type="file" name="file_video" />
  52. <input type="submit" name="upload" value="Kirim" />
  53. </form>
  54. </fieldset>
  55. <?php
  56. }
  57. ?>
  58. </div>
  59. </body>
  60. </html>
  61. <?php
  62. function autonumber()
  63. {
  64. //query yang mendapatkan id terbaru + 1
  65. //select max(id) from auto_number;
  66.  
  67. return $id;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement