Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. var canvas = document.getElementById("theCanvas");
  2. var img = canvas.toDataURL("image/png");
  3. $.ajax({
  4. type: 'POST',
  5. url: 'http://********/ImageUpload.php',params: {img: img},
  6.  
  7. success: function (msg)
  8. {
  9. alert("Done, Picture Uploaded.");
  10. }
  11. });
  12.  
  13. <?php
  14. define('UPLOAD_DIR', '/pic');
  15. $img = $_POST['img'];
  16. $img = str_replace('data:image/png;base64,', '', $img);
  17. $img = str_replace(' ', '+', $img);
  18. $data = base64_decode($img);
  19. $file = UPLOAD_DIR . uniqid() . '.png';
  20. $success = file_put_contents($file, $data);
  21. print $success ? $file : 'Unable to save the file.';
  22. ?>
  23.  
  24. $query = "INSERT INTO item(title, description, price) values('".$_GET['title']."', '".$_GET['description']."', ".$_GET['price'].")";
  25.  
  26. $stmt = $conn->query($query);
  27. $item_id = mysql_insert_id($conn);
  28.  
  29. $query = "INSERT INTO item_pic(path, item_id) values('".$_GET['path']."', '".$_GET['item_id'].")";
  30.  
  31. $stmt = $conn->query($query);
  32.  
  33. $.ajax({
  34. type: "POST",
  35.  
  36. url: "http://*****/*****/AddProduct/create.php?title="+ ($("#myTitle").val())+"&description="
  37. +$("#myDesc").val()+"&price="+$("#myPrice").val(),
  38. success: function(data){
  39. alert("inserted");
  40. }});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement