Drupal sends a file through cURL Post_PHP tutorial

WBOY
Release: 2016-07-13 10:44:03
Original
894 people have browsed it

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

$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);
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

$response

is the HTML output after the web form is submitted. http://www.bkjia.com/PHPjc/633136.htmlwww.bkjia.com
true
http: //www.bkjia.com/PHPjc/633136.html
TechArticleThis 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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!