php - 使用 php 将图像上传到 imgur

标签 php api curl imgur

我正在使用 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/

相关文章:

javascript - 推迟广告脚本执行

php - Hadoop 应用程序开发和 PHP

php - 自动选择带有pomm项目的特定hstore

python - Quickbase模块add_record()函数——文件上传参数?

java - android 的 mediawiki 语法分析器

curl 命令的 Javascript 等价物

php - 创建 iCal 事件,而不创建日历

php - 如何获取先前使用 curl_setopt() 设置的选项?

php - 如何使用 PHP cURL 发送具有正确内容类型的图像?

php - 获取拼写检查器/更正 API?