2017-07-17 4 views

Antwort

0

einen Blick auf dieses Paket haben, das ist ein super einfach curl Wrapper für Laravel https://github.com/ixudra/curl

so wäre es

use Ixudra\Curl\Facades\Curl; 

    $response = Curl::to('https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key=xxxxa12345&version=2016-05-20') 
    ->withContentType('multipart/form-data') 
    ->withData(['images_file' => file_get_contents("yourfile")]) 
    ->containsFile() 
    ->post(); 
+0

Ich bekomme Syntaxfehler, unerwartete '->' (T_OBJECT_OPERATOR) auf der -> withData Zeile – DanielA

+0

yeah es verpasste eine Klammer, ich konvertierte Array in kurze Syntax, so ist es klarer Entschuldigung dafür :) –

0

Es gibt eine Funktion, um Upload-Datei aussehen locken php:

function uploadFileWithCURL($fullFilePath, $targetURL) 
{ 
    if (function_exists('curl_file_create')) { 
     $curlFile = curl_file_create($fullFilePath); 
    } else { 
     $curlFile = '@' . realpath($fullFilePath); 
    } 
    $post = array('file_contents' => $curlFile); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $targetURL); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $result = curl_exec($ch); 
    curl_close($ch); 

    return $result; 
} 

Verwendung:

$result = uploadFileWithCURL('path/to/your/fruitbowl.jpg','https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key=xxxxa12345&version=2016-05-20');