Home > php教程 > php手册 > Drupal 通过cURL Post方式发送一个文件

Drupal 通过cURL Post方式发送一个文件

WBOY
Release: 2016-06-13 09:47:21
Original
829 people have browsed it

本文章来给大家介绍一个Drupal 通过cURL Post方式发送一个文件实现,如果你正在使用Drupal cms不防进入参考一下哦。

众所周知PHP的cURL扩展可以用来模拟表单提交。在Drupal中有drupal_http_request函数来执行一个HTTP请求,它可以通过POST方式来发送一个文件,但是使用起来没有cURL那么方便。 这里我们主要讲解如何在Drupal中Post一个文件到远程的服务器地址。

网页Form表单

 代码如下 复制代码





上面表单包含了演示文本框、密码、复选框和文件形式的提交。

Drupal cURL模拟表单提交POST

 代码如下 复制代码

$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

的值为网页Form表单提交后输出的HTML。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template