Answer the question
In order to leave comments, you need to log in
Why does cURL pass the path to the file to the server instead of the file?
Good afternoon!
I'm trying to set up a file transfer using PHP (cURL) from one server to another. On the sending server, the script looks like this:
<?php
$cho = curl_init();
$postdata['file'] = '@/var/www/html/file.jpg';
curl_setopt($cho, CURLOPT_URL, 'https://site.ru/upload.php');
curl_setopt($cho, CURLOPT_POST, true);
curl_setopt($cho, CURLOPT_POSTFIELDS, $postdata);
curl_exec($cho);
curl_close($cho);
?>
<?php
print_r($_POST);
echo '<br>';
print_r($_FILES);
?>
Array ( [file] => @/var/www/html/file.jpg )
Array ( )
Answer the question
In order to leave comments, you need to log in
php.net/manual/en/function.curl-setopt.php
CURLOPT_SAFE_UPLOAD
TRUE to disable support for the @ prefix for uploading files in CURLOPT_POSTFIELDS, which means that values starting with @ can be safely passed as fields. CURLFile may be used for uploads instead.
Added in PHP 5.5.0 with FALSE as the default value. PHP 5.6.0 changes the default value to TRUE.
curl_setopt($cho, CURLOPT_SAFE_UPLOAD, false); // required as of PHP 5.6.0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question