Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andyandy's avatar

Help with cURL and sending file, please?

I have to send cURL with 2 parameters and 1 file. Requirements are a little bit complicated for me:

//parameters
token = HrMHg2k8vcDC3pNU81X80ei9ijmHNAMy
type = xml
file


//send with encoding multipart/form-data
//data are separated by "boundary"
//data are identified by name "file"
//name of original file is handed over in parameter filename or in header content-disposition: form-data

Can you help, please?

0 likes
1 reply
andyandy's avatar

I understand general idea of cURL

$localFile = $_FILES[$fileKey]['tmp_name']; 

$fp = fopen($localFile, 'r');

// Connecting to website.
$ch = curl_init();

curl_setopt($ch, CURLOPT_USERPWD, "[email protected]:password");
curl_setopt($ch, CURLOPT_URL, 'ftp://@ftp.website.net/audio/' . $strFileName);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 86400); // 1 Day Timeout
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'CURL_callback');
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localFile));
curl_exec ($ch);

What I'm struggling with are all these requirements.

//send with encoding multipart/form-data
//data are separated by "boundary"
//data are identified by name "file"
//name of original file is handed over in parameter filename or in header content-disposition: form-data

For example how I identify data by name "data"? Why am I handing over parameter original filename, when I'm handing over data from file itself? Etc.

Please or to participate in this conversation.