1

i have a form with one file input and a submit button, The action attribute of the form set to 'upload.php' where i have my php script to rename the file and save it to a specific folder, But also i need some javascript variables for resizing and cropping the uploaded image. What is the best way to send them both at the same time to be used by php script.

Thanks you very much..

this is javascript code:

    $('.upload_form').submit(function(){
  var crop_position_top = $('.crop_div').position().top;
  var crop_position_left = $('.crop_div').position().left;
  var img_position_top = $('.upload_preview').position().top;
  var img_position_left = $('.upload_preview').position().left;

  var crop_start_x = img_position_left - crop_position_left;
  var crop_start_y = img_position_top - crop_position_top;

  var crop_tool_width = $('.crop_div').width();
  var crop_tool_height = $('.crop_div').height();

  var img_name = $('.upload_img_input').val();
  $.post("upload.php", {start_x: crop_start_x, start_y: crop_start_y, crop_width: crop_tool_width, crop_height:crop_tool_height});

});
6
  • Will you please provide some example code to investigate this issue ? Commented Sep 10, 2016 at 4:13
  • Please provide a sample code to test Commented Sep 10, 2016 at 4:14
  • May be below link will help you out stackoverflow.com/questions/2434458/… Commented Sep 10, 2016 at 4:16
  • try it webmotionuk.com/jquery-image-upload-and-crop-for-php Commented Sep 10, 2016 at 4:17
  • @AnkitDoshi that's my js code i used, when i try to echo the posted js values it says Undefined indexes, while the file is posted successfully. Commented Sep 10, 2016 at 4:28

1 Answer 1

1

You can add hidden input such as

And you can dynamically allocate value using javascript based on your action

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.