dimanche 17 mai 2015

Issue passing parameter to PHP script

I have created a media library in my cms and the option to edit media using jcrop.js but when i use static images in edit_media and crop.php.

Everything works fine when i use dynamic image from my db. edit_media works fine but when i hit crop to crop the image with crop.php I can't pass the same value of $img_name. What is the right query to do in crop.php to show the same image as edit_media ?

      if(isset($_GET['edit_media'])){

        $the_img_id = $_GET['edit_media'];

      }

      $query = "SELECT * FROM images WHERE img_id = $the_img_id";
      $select_img_by_id = mysqli_query($connection,$query);


        while($row = mysqli_fetch_assoc($select_img_by_id)) {
        $img_id = $row['img_id'];
        $img_name = $row['img_name'];


      }
    ?>    


    <div role="tabpanel">

      <!-- Nav tabs -->
      <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
        <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
        <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
        <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
      </ul>

      <!-- Tab panes -->
      <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home">

         <div id="wrapper">
      <div class="jc-demo-box">
        <header>
          <h1><span>Jcrop Live Avatar Demo</span></h1>
        </header>

        <img src="uploads/<?php echo $img_name ?>" id="target" alt="[Jcrop Example]" />



        <div id="form-container">
          <form id="cropimg" name="cropimg" method="post" action="crop.php" target="_blank">
            <input type="hidden" id="x" name="x">
            <input type="hidden" id="y" name="y">
            <input type="hidden" id="w" name="w">
            <input type="hidden" id="h" name="h">
            <input type="submit" id="submit" value="Crop Image!">
          </form>
        </div><!-- @end #form-container -->
      </div><!-- @end .jc-demo-box -->
    </div> 



        </div>
        <div role="tabpanel" class="tab-pane" id="profile"></div>
        <div role="tabpanel" class="tab-pane" id="messages"></div>
        <div role="tabpanel" class="tab-pane" id="settings"></div>
      </div>

    </div>
    <script>
      $(function () {
        $('#myTab a:last').tab('show')
      })
    </script>

crop.php

  <?php
 include "../includes/db.php";



  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $targ_w = $targ_h = 150;
  $jpeg_quality = 90;

  if(!isset($_POST['x']) || !is_numeric($_POST['x'])) {
    die('Please select a crop area.');
  }
  $src = 'uploads/'.$img_name.'jpg';

  $img_r = imagecreatefromjpeg($src);
  $dst_r = ImageCreateTrueColor($targ_w, $targ_h);

  imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
  $targ_w,$targ_h,$_POST['w'],$_POST['h']);
  $output_file = 'uploads/jcrop'.$img_name.'jpg';


  imagejpeg($dst_r, $output_file,$jpeg_quality); 

  exit;


}
?>




Aucun commentaire:

Enregistrer un commentaire