如何使用变量在文件夹中移动图像

时间:2015-11-24 11:58:36

标签: php jquery

我想插入原始图像和裁剪图像的值,我已经完成了裁剪图像。原始图像我已经传递了ajax中的src值,下一页我得到的值并插入该值,但不知道如何在一个文件夹中移动图像

   <div class="img-container">
      <img src="img/cropped-images/picture.jpg" alt="Picture">
    </div>
    <script>
        var original_image = $('img').prop('src');  
         $.ajax({
                        type:'POST',
                        url: "new_crop_image.php",
                        data: ({
                            'crop': result.toDataURL(),//this value i got and working fine
                            'image_var': original_image//this one not working,

                            }),
              }); 
     </script>

define('UPLOAD_DIR', 'img/cropped-images/');
$img = $_REQUEST['crop'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
$result=$success ? $file : 'Unable to save the file.';
$explode=explode("/",$result);
$count=count($explode);
//echo $count.'<br>';
for( $i = 0; $i < $count; $i++ )
 {
if($i==2){
  $filename = $explode[2];  
 }
 }

include('dbconfig.php');
$ssmid='SSM_offline128';
$status='0';
$approve='NO';
$reg_date=date('Y-m-d H:i:s');
$image = $_REQUEST['image_var'];//http://192.168.9.5/new/KANI/image-    cropper/img/cropped-images/picture.jpg  
$explode=explode("/",$image);/*  Array
                        (
                            [0] => http:
                            [1] => 
                            [2] => 192.168.9.5
                            [3] => new
                            [4] => KANI
                            [5] => image-cropper
                            [6] => img
                            [7] => cropped-images
                            [8] => picture.jpg
                        ) */

$original_image=$explode[8];// picture.jpg
$sql=mysql_query("INSERT INTO user_timeline_photos(ssmid,image,original_image,status,date_uploaded,timelinephoto_approved) VALUES('$ssmid','$filename','$original_image','$status',' $reg_date','$approve')");

0 个答案:

没有答案