This article will introduce you to a Drupal implementation of sending a file through cURL Post. If you are using Drupal cms, feel free to check it out for reference.
It is well known that PHP’s cURL extension can be used to simulate form submission. There is the drupal_http_request function in Drupal to perform an HTTP request. It can send a file through POST, but it is not as convenient to use as cURL. Here we mainly explain how to post a file to a remote server address in Drupal.
Web Form
The form above contains demonstration text boxes, passwords, check boxes and file submissions.
Drupal cURL simulates form submission POST
The code is as follows
代码如下 |
复制代码 |
$url = ‘http://blog.lixiphp.com/demo/http_request/post.php’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
‘username’ => ‘lixiphp’,
‘password’ => ’123456′,
‘rememberme’ => ’1′,
‘avatar’=> ‘@’.$filename,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$response
|
|
Copy code
|
|
$url = ‘http://blog.lixixp.com/demo/http_request/post.php’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
‘username’ => ‘lixixp’,
‘password’ => ’123456′,
‘rememberme’ => ’1′,
‘avatar’=> ‘@’.$filename,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$response
The value of is the HTML output after the web form is submitted.
http://www.bkjia.com/PHPjc/633136.htmlwww.bkjia.com
trueTechArticleThis article will introduce to you a Drupal implementation of sending a file through cURL Post. If you are using Drupal cms Please refer to it to prevent entry. As we all know, PHP’s cURL extension can...