PHP Asynchronous processing-Uploading files

Source: Internet
Author: User
Tags curl upload file

This article mainly introduces about PHP asynchronous processing-upload files, has a certain reference value, now share to everyone, have the need for friends can refer to the

Fsockopenpublic function Testfsockeopen () {$cookie = $_cookie; $url = ' Http://localhost/jtzn/src/server/index.php/Admin/Station/submitimp '; The file address of the asynchronous trigger $url _array = Parse_url ($url); Parse URL $port = isset ($url _array[' Port ')?                $url _array[' Port ']: 80;                $errno = ";                $errstr = ";                $timeout = 30; $fp = Fsockopen ($url _array[' host '), $port, $errno, $errstr, $timeout);        Turn on if (! $fp) {return false; }//Analog data $boundary = "----".                SUBSTR (MD5 (Time ()), 8, 16);                $data = "--$boundary \ r \ n"; foreach ($_files as $key = = $file) {$data. = "Content-disposition:form-data; Name=\ "". $key. "\"; Filename=\ "". $file [' name '].                    "\" \ r \ n "; $data. = "Content-type:". $file [' type '].                    "\r\n\r\n"; $data. = file_get_contents ($file [' tmp_name ']).                    "\ r \ n"; $data. = "--$Boundary--\r\n ";                }//Build request Header $header = "POST $url _array[path] http/1.1\r\n";                $header. = "Host: $url _array[host]\r\n"; $header. = "Content-type:multipart/form-data;                boundary= $boundary \ r \ n "; $header. = "Content-length:". Strlen ($data).                "\ r \ n";                $_cookie = Strval (NULL); foreach ($cookie as $k = = $v) {$_cookie. = $k. "=" .        $v; } $cookie _str = "Cookie:". $_cookie. "\ r \ n";                The pass-through cookie is used for login verification $header. = $cookie _str;                $header. = "connection:close\r\n\r\n";        $header. = $data;        Fwrite ($fp, $header);                Do not receive the return of the server, so you do not have to wait for fclose ($FP);    Echo Json_encode ([' msg ' = ' OK ', ' info ' = ' already initiated application ');                } public Function Testcurl () {$url = ' http://localhost/jtzn/src/server/index.php/Admin/Station/submitimp ';                $file = $_files[' updataexcel2007 '); $post _data[' updataexcel2007 ' = Curl_file_create (Realpath ($file [' tmp_name ']), $file [' type '], $file [' name ']);                Curl Upload File $ch = Curl_init ();                $cookie = $_cookie;                $_cookie = Strval (NULL); foreach ($cookie as $k = = $v) {$_cookie. = $k. "=" .        $v;        } curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer, 1);//Whether the execution result is returned, 0 is returned, 1 is not returned curl_setopt ($ch, Curlopt_header, 1);//parameter setting, whether the header is displayed        Department information, 1 for display, 0 for not showing//form data, is the formal form setting value is not 0 curl_setopt ($ch, Curlopt_post, 1);        curl_setopt ($ch, curlopt_timeout, 1); curl_setopt ($ch, Curlopt_cookie, $_cookie);        Login Verification curl_setopt ($ch, Curlopt_postfields, $post _data);        Curl_exec ($ch);                Curl_close ($ch);    Echo Json_encode ([' msg ' = ' OK ', ' info ' = ' already initiated application '); }

Above is the entire content of this article, more relevant content please pay attention to topic.alibabacloud.com.

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.