Jumat, 20 Januari 2017

Upload foto dg kompresi di klient (PHP) bagian 3

Full Coding Upload foto dg kompresi di klient menggunakan PHP


ini syntax keseluruhan di halaman pertama



<style type="text/css">
<!--
body {
 margin-left: 0px;
 margin-top: 0px;
 margin-right: 0px;
 margin-bottom: 0px;
}
-->
</style>
<script type="text/javascript">
    function ShowLoading(e) {
        var div = document.createElement('div');
        var img = document.createElement('img');
        img.src = 'image/loading_bar.gif';
        div.innerHTML = "Loading...<br />";
        div.style.cssText = 'position: fixed; top: 160; left: 42%; z-index: 5000; width: 202px; text-align: center; background: #EDDBB0; border: 1px solid #000';
        div.appendChild(img);
        document.body.appendChild(div);
        return true;
        // These 2 lines cancel form submission, so only use if needed.
        //window.event.cancelBubble = true;
        //e.stopPropagation();
    }
</script>

<table width="100%" bgcolor="#444C4F" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<div align="center">
<img src="image/Header_Mobile.jpg" />
</div>
</td>
</tr>
</table>
<br />
<br />


<?php
include("lib/config.php");
//include("session.php");

$today = date("ymjgis");
//echo "tanggal hari ini : ".$today;

    if(isset($_POST['submit'])){
?>

<div align="center"> 
<h2>Langkah 3. Masukkan ruangan dan penjelasan (lalu klik save)</h2>
<form method="post" enctype="multipart/form-data"  action="terimaorder.php?simpandatanya=yes&name=<? echo $imagepath; ?>">
<table width="100%">
 <tr>
    <td bgcolor="#CCCCCC"><div align="right">Kode Work Order </div></td>
    <td>
      <input name="kodewo" type="text" value="<? echo $today; ?>"  size="25" maxlength="20" />
 </td>
 </tr>
 <tr>
    <td bgcolor="#CCCCCC"><div align="right">Ruangan:</div></td>
    <td>
      <input name="ruanganwo" type="text" value=""  size="50" maxlength="73" />
 </td>
 </tr>

 <tr>
    <td bgcolor="#CCCCCC"><div align="right">Penjelasan WO</div></td>
    <td>
    <textarea name="keteranganwo" cols="50" rows="5"></textarea>
 </td>
 </tr>

<tr>
<td colspan="2">
<!--  <p>&nbsp;</p>
  <p>klik disini untuk upload gambar:</p>
  <p>
   <input type="file" name="myFile">
   <a href="tambahgambarbaru.php"><img src="image/camera.png" border="0"></a>
   </p>
  
   -->
 
  <br>
   
    </td>
</tr>

</table>

















<p>
  <?
      $myFile = $_FILES["new_image"];
 
      if (isset ($_FILES['new_image'])){
          $imagename = $_FILES['new_image']['name'];
          $source = $_FILES['new_image']['tmp_name'];
          $target = "".$imagename;
        //  move_uploaded_file($source, $target);
          $imagepath = $imagename;
          $save = "upload/" . $imagepath; //This is the new file you saving
         // $file = $imagepath; //This is the original file di hp
          list($width, $height) = getimagesize($source) ;

          $tn = imagecreatetruecolor($width, $height) ;
          $image = imagecreatefromjpeg($source) ;
       //   $image = imagecreatefromjpeg($file) ;
        //  imagecopyresampled($tn, $image, 0, 0, 0, 0, $width, $height, $width, $height) ;
        //  imagejpeg($tn, $save, 70) ;
          $save = "upload/" . $imagepath; //This is the new file you saving
        //  $file = "upload/" . $imagepath; //This is the original file
         // list($width, $height) = getimagesize($file) ;
          list($width, $height) = getimagesize($source) ;
         
    if ( $width >=1024)
    { $modwidth = 1024; }
    else
    { $modwidth = $width; }
          //$modwidth = $width/2;
          $diff = $width / $modwidth;
         // $modheight = 185;
          $modheight = $height/$diff;
   
          $tn = imagecreatetruecolor($modwidth, $modheight) ;
        //  $image = imagecreatefromjpeg($file) ;
          $image = imagecreatefromjpeg($source) ;
         // $image = imagecreatefromjpeg($save) ;
          imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
          imagejpeg($tn, $save, 70) ;
   
   
   
        //echo "Large image: <img src='upload/".$imagepath."'><br>";
  //echo $imagepath;
        echo "<img src='upload/".$imagepath."'>";
      }
?>
</p>
     <input name="name" type="hidden" value="<? echo $imagepath; ?>"  />
    <input type="image" src="image/save.jpg" border="0" alt="Submit" />
</form>
</div>
<?  
  
  
  
  
    }
 else
 {

 ?>
<div align="center">   
    <h1>
   
   <!-- <a href="menu.php"><img src="image/backsmall.jpg" border="0" /></a>  <br /> -->
   
    Tambah work order baru <br />
   
   
    <?
$sqlcabangselect = " select * from cabang where idcabang = $cabang ";
$resultcabangselect = mysql_query($sqlcabangselect);
 while ($rs = mysql_fetch_array($resultcabangselect))
{
$namacabang=$rs['namacabang'];
echo $namacabang;
}
?>
 </h1>  
   
    <h2>Langkah 1. Klik "Choose File" untuk pilih gambar jpg atau langsung foto <br>
    </h2>
   
   
<form action="" method="post" enctype="multipart/form-data" id="something" class="uniForm" runat="server"  onsubmit="ShowLoading()"> 
<input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /> <br /><br /><br /><br /><br /><br />
  <!--      <input type="image" src="image/save.jpg" border="0" alt="Submit" class="submitButton"/> -->
  <h2>Langkah 2. Klik SAVE IMAGE <br>
    </h2>
    <button name="submit" type="submit" class="submitButton">Upload / Save Image</button>

 
<? } ?>

 

---------------------------------------------------------------------------------------------

Yang ini untuk file simpen nama gambar ke data base:(terimaorder.php)

<?php
include("lib/config.php");
//include("session.php");

$today = date("ymjgis");
if ($simpandatanya==yes)
{
$sql1x = "  insert into wo (kodewo,ruanganwo,keteranganwo,gambarwo)
 values
 ('$kodewo','$ruanganwo','$keteranganwo','$name')
 ";
$result1x = mysql_query($sql1x);
//echo $sql1x ;

echo "<div align='center'><a href='progress.php'>data WO telah di simpan klick disini untuk lihat<br><img src='image/progress.jpg'  border='0' /></a></div> ";
}
?>

-----------------------------------------------------------------------------------------

semoga bermanfaat.

- lihat disini untuk kajian
- lihat disini untuk penjelasan syntax



Tidak ada komentar:

Posting Komentar