小编0g8*_*4eh的帖子

使用 cURL 通过 PHP 将文件发送到 API

我正在尝试将文件上传到此 API:http://www.noelshack.com/api.php 我对 cURL 一无所知。我找到了示例代码,并且尝试了以下方法:

<?php

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.noelshack.com/api.php');

// send a file
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt(
    $curl,
    CURLOPT_POSTFIELDS,
    array(
      'fichier' => '@http://cdn.soccerwiki.org/images/player/2386.jpg'
    ));

// output the response
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
print_r($result);

curl_close($curl);

?>
Run Code Online (Sandbox Code Playgroud)

任何人都可以用我当前的代码来解释我不起作用吗?它应该返回这样的网址:http://www.noelshack.com/2016-XX-XXXXXXXXXX-2386.png

但它没有返回任何东西。我的代码中没有任何错误,文件只是没有上传,我不知道为什么,因为我不知道如何显示 api 错误!

提前致谢

(抱歉我的英语不好,我是法国人)

php api curl

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

api ×1

curl ×1

php ×1