I'm trying to send a .txt file via php curl post request to get its contents but no success.
The point is that if I make a var_dump($_FILES)
as $result
being $result
the curl_exec($ch)
response it shows me an empty array but if I try it with $_POST
:
array(
[uploaded_file] =>
[name] => 'absolute/path/to/file.txt'
[mime] => 'text/plain'
[postname] => 'file.txt'
)
How can I pass that file as a $_FILES variable?
This is my curl send.php curl script:
$filedata = curl_file_create('../path/to/file.txt', 'text/plain', 'file.txt');
$array = array(
'file' => $filedata
)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://domain_name.com/url/to/script.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
$result = curl_exec($ch);
curl_close($ch);
This is the receive.php script:
if(file_exists($_FILES['uploaded_file']['tmp_name']) && is_uploaded_file($_FILES['uploaded_file']['tmp_name'])){
$contents = file_get_contents($_FILES['uploaded_file']['tmp_name']);
$data = explode('/',$contents);
}
but it's never entering the if statement...