Rocky Pocky
Rocky Pocky

Reputation: 11

imageshack API cURL

I now the credentials are correct.

When I send a image through Form like this:(action="http://api.imageshack.com/v2/images/"). Its working fine but When I tried to send $ch = curl_init($url); Its failed.

CODE:

enter code here
<form action="" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="file" id="file" multiple>
    <input type="text" name="auth_token" id="auth_token" value="xxxxxxxxxxxxxxxx">
    <input type="text" name="api_key" id="api_key" value="xxxxxxxxxxxxxxx">

    <input type="submit" value="Upload Image" >
</form>

$url = 'http://api.imageshack.com/v2/images/';

    $temp = $_FILES["file"]['tmp_name'];

    echo $temp."<br>" ;

  $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_POST, true);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_TIMEOUT, 240);

    curl_setopt($ch, CURLOPT_POSTFIELDS, array( 
      'file'=> '@'.$temp, 
      "key" => "xxxxxxxxxxxxxxxxxxxx",
      "auth_token" => "xxxxxxxxxxxxxxx"          

      ));
curl_exec($ch);

I have also tried with Header: curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

And i get error from imageshack as json: {"error_code":1,"error_message":"Invalid image file. The file uploaded is not being detected as an image file.","error_info":{"Content-Type":null,"filesize":0}}

Upvotes: 1

Views: 259

Answers (0)

Related Questions