Page 1 sur 1

envoi fichier tar en CURL

Posté : 04 avr. 2022, 14:43
par cdsoft
Bonjour a tous,
je rencontre un soucis lors d'un envoi en CURL d'un site 1 vers un un site 2 , d'un fichier .tar.
Plus précisément lors du file_put_contents(__DIR__.'/recups/'.$resp->name, $filebin);

je reçois bien mon fichier mais sa création dans le répertoire de destination est endommagé

code envoi :



$archive = new PharData($nameZip);
$archive->buildFromDirectory($pathZip);


$data=array(
'name' => $nameZip,
'file' => base64_encode(file_get_contents($path))
);

$ch = curl_init();
$options = array(CURLOPT_URL => 'https://monUrl/monFichier.php?pkey=xxxxxxxx',
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => true, //Request header
CURLOPT_HEADER => true, //Return header
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_SSL_VERIFYPEER => false, //Don't veryify server certificate
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data)
);

curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$header_info = curl_getinfo($ch,CURLINFO_HEADER_OUT);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
curl_close($ch);



code réception :

$body = file_get_contents('php://input');

$resp = json_decode($body);

$filebin = base64_decode($resp->file);


file_put_contents(__DIR__.'/recups/'.$resp->name, $filebin);



Merci a vous

Re: envoi fichier tar en CURL

Posté : 06 avr. 2022, 08:51
par @rthur
Pourquoi tu ne fais pas juste un envoi standard comme si tu avais un formulaire d'upload sur ton site de réception ?
Car un json_encode/decode sur un fichier binaire, j'ai un doute sur le fait que ça puisse fonctionner.

https://www.php.net/manual/fr/function. ... create.php