envoi fichier tar en CURL

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : envoi fichier tar en CURL

Re: envoi fichier tar en CURL

par @rthur » 06 avr. 2022, 08:51

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

envoi fichier tar en CURL

par cdsoft » 04 avr. 2022, 14:43

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