Advertisement
Guest User

Untitled

a guest
May 19th, 2021
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. function telegraph_upload($file) {
  2. $curl_file = curl_file_create($file);
  3. $curl_file->mime = mime_content_type($file);
  4. $curl_file->postname = 'blob';
  5.  
  6. $post = ['file' => $curl_file];
  7.  
  8. $ch = curl_init('https://telegra.ph/upload');
  9. curl_setopt($ch, CURLOPT_POST, 1);
  10. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12. $request = curl_exec($ch);
  13. curl_close($ch);
  14.  
  15. $request = json_decode($request);
  16. $src = $request[0]->src;
  17.  
  18. if (!$src) {
  19. return (object) [
  20. 'ok' => false,
  21. 'error' => $request->error
  22. ];
  23. }
  24.  
  25. return (object) [
  26. 'ok' => true,
  27. 'path' => $src,
  28. 'url' => 'https://telegra.ph' . $src
  29. ];
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement