I'm trying to use PHP curl to submit a payload with some files. Here's my submit.php
<?php
$url = "http://example.com/receive.php";
$payload = array();
$payload['resource_name'] = 'hello world';
$payload['resource_file'] = curl_file_create("test-pdf.pdf");
$headr = array();
//$headr[] = 'Content-Type: multipart/form-data';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($payload));
// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);
print_r($response);
echo "\n";
And this is my http://example.com/receive.php
<?php
print_r($_REQUEST);
print_r($_FILES);
When I run php submit.php from command line I get this result:
Array
(
[resource_name] => hello world
[resource_file] => Array
(
[name] => test-pdf.pdf
[mime] =>
[postname] =>
)
)
Array
(
)
Why is my $_FILES array empty?
If I enable the multipart/form-data line, then both $_REQUEST and $_FILES is empty. What am I doing wrong? How do I populate both the $_REQUEST and $_FILES array in receive.php?