I have a command which I run on linux terminal like below:

curl –W “Authentication: Token r4r4xxxxx” “https://api.com/v1/results?display=true&format=image/jpeg&lang=en” –o image.jpg

And this command will authenticate me from the server and download the image named image.jpg to my local machine from where I am calling this command… But I am looking for a way to do this either in Ajax or Jquery or PHP would do… This is a web based application which will fetch a specific image from an API…. As I am trying to write a user friendly interface for users to be able to use this… I would like to know how can I replicate the same command above using any web based technology and how to pass parameters and both strings in quotes how would I pass them as I need them both.

1 Year
Discussion Span
Last Post by cereal

Hi, which version of curl are you using? I don't have the -W option and I don't find it in the documentation.

Have you tried the PHP curl library? http://php.net/manual/en/book.curl.php
Also you could use Guzzle: http://docs.guzzlephp.org/en/latest/

An example with Guzzle:


require_once dirname(__DIR__) . '/vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

$config = ['connect_timeout' => 30
         , 'timeout' => 30
         , 'debug'   => TRUE
         , 'headers' => ['Authorization' => 'Token r4r4xxxxx']];

$client   = new Client();
$resource = fopen(tempnam('/tmp/', 'image_'), 'w');
$request  = new Request('GET', 'https://link/to/api/');

$client->send($request, array_merge($config, ['sink' => $resource]));

If you run this into a terminal you can see a verbose log of request and response, to disable just set debug to false or simply remove it from the config array.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.