note 110117 added to function.curl-setopt

From: Date: Fri, 21 Sep 2012 06:01:56 +0000
Subject: note 110117 added to function.curl-setopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-190943@lists.php.net to get a copy of this message
fixed ambiguous of the first @ character <?php /** * php-curl-lib * author: selfimpr * blog: http://blog.csdn.net/lgg201 * mail: lgg860911@gmail.com */ define('API_CURL_UPLOAD_FILE', '__file'); define('MULTIPART_FORM_DATA_HEAD_FMT', 'Content-Type: multipart/form-data; boundary=----------------------------%s'); define('MULTIPART_FORM_DATA_BODY_STRING', "------------------------------%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n"); define('MULTIPART_FORM_DATA_BODY_FILE', "------------------------------%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\nContent-Type: application/octet-stream\r\n\r\n%s\r\n"); define('MULTIPART_FORM_DATA_BODY_END', "------------------------------%s--\r\n\r\n"); function __datas_set($curl, $datas = NULL) { if ( empty($datas) ) return ; if ( is_array($datas) ) { $custom_body = FALSE; $uniqid = uniqid(); $custom_body_str = ''; foreach ( $datas as $name => $data ) { if ( is_array($data) && array_key_exists(API_CURL_UPLOAD_FILE, $data) ) { $file = $data[API_CURL_UPLOAD_FILE]; if ( file_exists($file) ) { $custom_body = TRUE; $custom_body_str .= sprintf(MULTIPART_FORM_DATA_BODY_FILE, $uniqid, $name, $file, file_get_contents($file)); } } else { $custom_body_str .= sprintf(MULTIPART_FORM_DATA_BODY_STRING, $uniqid, $name, $data); } } if ( $custom_body ) { curl_setopt($curl, CURLOPT_HTTPHEADER, array(sprintf(MULTIPART_FORM_DATA_HEAD_FMT, $uniqid))); $datas = $custom_body_str . sprintf(MULTIPART_FORM_DATA_BODY_END, $uniqid); } } curl_setopt($curl, CURLOPT_POSTFIELDS, $datas); } function curl_post_file($file) { return array( API_CURL_UPLOAD_FILE => $file, ); } ---- Server IP: 69.147.83.199 Probable Submitter: 123.124.206.69 ---- Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php Edit -- https://master.php.net/note/edit/110117 Del: integrated -- https://master.php.net/note/delete/110117/integrated Del: useless -- https://master.php.net/note/delete/110117/useless Del: bad code -- https://master.php.net/note/delete/110117/bad+code Del: spam -- https://master.php.net/note/delete/110117/spam Del: non-english -- https://master.php.net/note/delete/110117/non-english Del: in docs -- https://master.php.net/note/delete/110117/in+docs Del: other reasons-- https://master.php.net/note/delete/110117 Reject -- https://master.php.net/note/reject/110117 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190943) next »