As we all know, PHP's cURL extension can be used to simulate form submission. in Drupal, there is the drupal_http_request function to execute an HTTP request. it can send a file through POST,
As we all know, PHP's cURL extension can be used to simulate form submission. in Drupal, there is a drupal_http_request function to execute an HTTP request. it can send a file through POST, but it is not as convenient as cURL, here we will mainly explain how to Post a file to a remote server address in Drupal.
The code of Form on the webpage is as follows:
-
The above form contains the submission of the demo text box, password, check box, and file Form. Drupal cURL simulates the form submission of 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' => 'lixip ',
- 'Password' => '000000 ′,
- 'Rememberme' => '1 ′,
- 'Avatar '=>' @ '. $ filename,
- );
- Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post );
- $ Response = curl_exec ($ ch );
- $ Response
The value is the HTML output after the webpage Form is submitted.