note 110117 deleted from function.curl-setopt by danbrown

From: Date: Thu, 06 Dec 2012 15:18:00 +0000
Subject: note 110117 deleted from function.curl-setopt by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192364@lists.php.net to get a copy of this message
Note Submitter: lgg860911 at gmail dot com ---- 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, ); }

« previous php.notes (#192364) next »