1
var name = $("#name").val();
$.ajax({
    type: "post",
    dataType: "json",
    url: "save.php",
    data: { 
        image: canvas.toDataURL(),
        name:name
    }
});

I'm trying to save my cropped image with name from get text field.

When I sent only imageurl its working. How can I fix this problem ?

save.php:

<?php

if($_SERVER['REQUEST_METHOD'] == "POST") {

    // location to save cropped image,
    $ad=$_POST['name'];
    $url = 'temp/"'.$ad.'".jpg';
    //$url = 'temp/one.jpg';

    // remove the base64 part
    $base64 = preg_replace('#^data:image/[^;]+;base64,#', '', $_POST['image']);
    $base64 = base64_decode($base64);

    $source = imagecreatefromstring($base64); // create

    imagejpeg($source, $url, 100); // save image

    // return URL
    $validation = array (
        'url'     => $url);
    echo json_encode($validation);
}
Paul T. Rawkeen
  • 3,994
  • 3
  • 35
  • 51
  • Are you saying that `$_POST['name']` is empty? – Alex Jul 09 '14 at 12:10
  • ajax type should be uppercased, but that's just a remark, I don't think it will solve your issues. – ffflabs Jul 09 '14 at 12:10
  • @amenadiel that's not true, look in jQuery source code. it normalizes either case – charlietfl Jul 09 '14 at 12:11
  • Is the post data urlencoded? Maybe the base64 String break things unencoded. – Bernhard Jul 09 '14 at 12:11
  • 1
    `$url = 'temp/"'.$ad.'".jpg';` will produce `$url = 'temp/"one".jpg';`, not `$url = 'temp/one.jpg';`. Why are you using `""` in a file name? – afaolek Jul 09 '14 at 12:12
  • @charlietfl I believe you, mate. But [RFC2616 states that http verbs are case sensitive](http://www.ietf.org/rfc/rfc2616.txt) (see section 5.1.1) If jQuery's flexible about that we never know when it could be changed. – ffflabs Jul 09 '14 at 12:15
  • cropping and saving image is working .but I want to save cropped image by my entered name in textfield. – user3191435 Jul 09 '14 at 12:17

0 Answers0