PHP Curl Posting @Sign Return False

I got this test code.

File name: test.php

<?php
$array = array(
            'host' => "@"
        );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/post.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$response = curl_exec($ch);
curl_close($ch);

var_dump($response);
?>

      

and this, post.php

<?php
  var_dump($_POST);
?>

      

Whenever I use the "@" value as a value, I get a false result like this,

bool(false)

      

but when i use "@" or "any @" i get this result

array(1) { ["host"]=> string(2) " @" }

      

any explanations and solutions about this?

Thank!

+3


source to share


1 answer


@

the prefix is ​​used to specify the path to the file (file upload).

You can disable the prefix @

by setting the option CURLOPT_SAFE_UPLOAD

(php version> = 5.5 needed) in TRUE

.



Or you can just use a query string instead of an array.

curl_setopt($ch, CURLOPT_POSTFIELDS, "host=@");

      

+5


source







All Articles