here is my code:
<?php
$url = 'http://localhost:2304/index.php/testproj/files/add/';
$name = "test";
$fields = array(
'name'=>urlencode($name)
);
$fields_string = "";
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
var_dump($result);
curl_close($ch);
?>
I am trying to send message data to a CodeIgniter controller. I decided to use CURL to do this work. however, it does not work, when I add "blah" to my controller, it does not return anything. When I access the URL directly, it shows “blah”.
source
share