Error in zip file import - CURL does not return UID

25 views
Skip to first unread message

Gustavo Cáceres

unread,
Feb 2, 2022, 10:57:14 AM2/2/22
to Orthanc Users

Hello! I have an error when using CURL in PHP, I do not have a return of the ID of the study created in Orthanc. When I try CURL in the command prompt (CMD), it does return a value on the screen. This is the PHP code that performs this function, can you help me where the error is: $cliente = curl_init();
$fileAttachment = new CURLFile(realpath('estudios/1001.zip'),'file/zip','1001.zip');
$fields = array(
    'files' => $fileAttachment
);
curl_setopt($cliente, CURLOPT_URL, "http://192.168.10.106/instances/");
curl_setopt($cliente, CURLOPT_POST, 1);
curl_setopt($cliente, CURLOPT_USERPWD, 'usuario:clave');
curl_setopt($cliente, CURLOPT_POSTFIELDS, $fields);
curl_setopt($cliente, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cliente, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$response = curl_exec($cliente);
$errors = curl_error($cliente);
$resultStatus = curl_getinfo($cliente);    
curl_close($cliente);                                
if($resultStatus['http_code'] == 200) {
    $respuesta=array("id" => 1, 'mensaje'=>'debe llegar', 'datos'=>json_decode($response), 'datos2'=>json_decode($response,1), 'datos3'=>$response, 'datos4'=>json_decode($response,1), 'error'=>json_decode($errors,1));
} else {
    $respuesta=array("id" => 0, 'mensaje'=>'No hay Conexión con el Servidor PACS','respuesta'=>$resultStatus, 'error'=>json_decode($errors,1));
}
echo json_encode($respuesta);

Sébastien Jodogne

unread,
Feb 2, 2022, 11:09:50 AM2/2/22
to Orthanc Users
Hello,

You must  *not* use "array()" in "CURLOPT_POSTFIELDS". The binary file must be provided as it. Here is a full sample:

(Disclaimer: untested, as this is a pure PHP question that is not specific to Orthanc).

Sébastien-
Reply all
Reply to author
Forward
0 new messages