Get the App
SLTechnology News&Howtos  ›  Development  › 

How does PHP respond to post requests to upload files

Shulou Source: shulou.com Published: 2022-06-03 19:40:46 11月12日 Update

This article is about how PHP uploads files in response to post requests. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

The details are as follows:

function send_file($url, $post = '', $file = '') { $eol = "\r\n"; $mime_boundary = md5 ( time () ); $data = ''; $confirmation = ''; date_default_timezone_set ( "Asia/Shanghai" ); $time = date ( "Y-m-d H:i:s " ); $post ["filename"] = $file [filename]; foreach ( $post as $key => $value ) { $data .= '--' . $mime_boundary . $eol; $data .= 'Content-Disposition: form-data; '; $data .= "name=" . $key . $eol . $eol; $data .= $value . $eol; } $data .= '--' . $mime_boundary . $eol; $data .= 'Content-Disposition: form-data; name=' . $file [name] . '; filename=' . $file [filename] . $eol; $data .= 'Content-Type: text/plain' . $eol; $data .= 'Content-Transfer-Encoding: binary' . $eol . $eol; $data .= $file [filedata] . $eol; $data .= "--" . $mime_boundary . "--" . $eol . $eol; $params = array ('http' => array ('method' => 'POST', 'header' => 'Content-Type: multipart/form-data;boundary=' . $mime_boundary . $eol, 'content' => $data ); $ctx = stream_context_create ( $params ); $response = file_get_contents ( $url, FILE_TEXT, $ctx ); return $response;} Thank you for reading! About "PHP how to respond to post requests upload files" This article is shared here, I hope the above content can have some help for everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Documents content more articles good practical articles read knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Linux OPPO Reno Shulou Tech Info