Uploading files to Imageshack API using HTML form, cURL and PHP

倾然丶 夕夏残阳落幕 提交于 2019-12-05 19:20:12

I had to include "format" => 'json' into the post options and use json_decode to parse the info. Here's the upload.php script.

<?php
    $url = 'http://imageshack.us/upload_api.php';
    $key = '4BEILRTV5ff57ecb70867e8becb2c4b5e695bdb4';
    $max_file_size = '5242880';
    $temp = $_FILES["fileupload"]["tmp_name"];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_URL, $url);

    $post = array(
        "fileupload" => '@' . $temp,
        "key" => $key,
        "format" => 'json',
        "max_file_size" => $max_file_size,
        "Content-type" => "multipart/form-data"
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $response = curl_exec($ch);
    $json_a=json_decode($response,true);
    echo $json_a[links][image_link];
?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!