Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function telegraph_upload($file) {
- $curl_file = curl_file_create($file);
- $curl_file->mime = mime_content_type($file);
- $curl_file->postname = 'blob';
- $post = ['file' => $curl_file];
- $ch = curl_init('https://telegra.ph/upload');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $request = curl_exec($ch);
- curl_close($ch);
- $request = json_decode($request);
- $src = $request[0]->src;
- if (!$src) {
- return (object) [
- 'ok' => false,
- 'error' => $request->error
- ];
- }
- return (object) [
- 'ok' => true,
- 'path' => $src,
- 'url' => 'https://telegra.ph' . $src
- ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement