Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. async function uploadImageAsync(uri) {
  2. let apiUrl = 'upload.php';
  3.  
  4.  
  5.  
  6. let uriParts = uri.split('.');
  7. let fileType = uriParts[uriParts.length - 1];
  8.  
  9. let formData = new FormData();
  10. formData.append('photo', {
  11. uri: uri,
  12. name: `photo.${fileType}`,
  13. type: `image/${fileType}`,
  14. });
  15.  
  16. let options = {
  17. method: 'POST',
  18. body: formData,
  19. headers: {
  20. Accept: 'application/json',
  21. 'Content-Type': 'multipart/form-data',
  22. },
  23. };
  24.  
  25. return fetch(apiUrl, options);
  26. }
  27.  
  28. move_uploaded_file($_FILES['photo']['tmp_name'], 'images/' . $_FILES['photo']['name']);
  29.  
  30. move_uploaded_file($_FILES['photo']['uri'], 'images/' . $_FILES['photo']['name']);
  31.  
  32. $data = json_decode(file_get_contents("php://input"));
  33. $file = $data->{"photo"};
  34. move_uploaded_file($file['uri'], 'images/' . $file['name']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement