Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. jQuery('.modal-footer .capture').click(function(){
  2. var target = jQuery('#manipulated-img')
  3. html2canvas(target, {
  4. onrendered: function(canvas) {
  5. var img = canvas.toDataURL()
  6. jQuery.ajax({
  7. data: {'action': 'store-img', 'img' : img},
  8. type: 'POST',
  9. url: ajaxurl,
  10. success:function(ret){
  11. jQuery('.product-addon-manipulated-image > p > input').val(ret)
  12. jQuery('#myModal').fadeOut()
  13. }
  14. })
  15. }
  16. });
  17. })
  18.  
  19. public function store_img() {
  20. //just a random name for the image file
  21. $random = md5( uniqid( mt_rand(), true ) );
  22.  
  23. //convert the binary to image using file_put_contents
  24. $dir = wp_upload_dir()['basedir'] . '/add-on';
  25. if ( ! file_exists( $dir ) ) {
  26. wp_mkdir_p( $dir );
  27. }
  28. $savefile = @file_put_contents( $dir . "/$random.png", base64_decode( explode( ",", $_POST['img'] )[1] ) );
  29. //if the file saved properly, print the file name
  30. if( $savefile ){
  31. echo wp_upload_dir()['baseurl'] . "/add-on/$random.png";
  32. } else{
  33. echo "failed";
  34. }
  35. die();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement