我正在使用 php 将图像上传到 imgur 这是我正在使用的代码:
$id = 'clientId';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Client-ID ' . $id));
curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'image' => base64_encode($image)));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$response = json_decode($response);
curl_close ($ch);
代码正在工作,但我希望将图像上传到我的帐户相册(如果有人知道如何做的话),我也试图理解为什么我必须设置 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
为了使代码正常工作,我确实访问了 manual但如果有人能给我一些关于如何以及为什么的背景知识,我将非常感激,谢谢大家,祝你有美好的一天。
最佳答案
您可以将这些参数与您的请求一起发送:
image required A binary file, base64 data, or a URL for an image
album optional The id of the album you want to add the image to. For anonymous albums, {album} should be the deletehash that is returned at creation.
type optional The type of the file that's being sent; file, base64 or URL
name optional The name of the file, this is automatically detected if uploading a file with a POST and multipart / form-data
title optional The title of the image.
description optional The description of the image.
那么,这个怎么样:
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image), 'album' => 1234));
关于php - 使用 php 将图像上传到 imgur,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20150448/