Drupal sends a file via Curl Post _php tutorial

Source: Internet
Author: User
Tags drupal
This article to introduce a Drupal through the Curl post to send a file implementation, if you are using Drupal cms do not go into the reference oh.

It is well known that PHP's curl extension can be used to simulate form submissions. There is a drupal_http_request function in Drupal to execute an HTTP request that can send a file by post, but it is not as easy to use as curl. Here we mainly explain how to post a file to a remote server address in Drupal.

Web Form Forms

The code is as follows Copy Code

The above form contains a presentation text box, a password, a check box, and a file in the form of a submission.

Drupal Curl Demo Form Submit post

The code is as follows Copy Code

$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

The value is the HTML that is output after the page form form is submitted.

http://www.bkjia.com/PHPjc/633136.html www.bkjia.com true http://www.bkjia.com/PHPjc/633136.html techarticle This article to introduce a Drupal through the Curl post to send a file implementation, if you are using Drupal cms do not go into the reference oh. It is well known that PHP's curl extension can ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.