Upload class
Class uploadpart{protected static $url; protected static $delimiter; protected static $instance; Public Function __construct () {static:: $url = ' http://files.note.so/v1/file_server '; Static:: $delimiter = Uniqid (); The Public Function Putpart ($param) {$post _data = Static::builddata ($param); $curl = Curl_init (static:: $url); curl_setopt ($curl, Curlopt_returntransfer, true); curl_setopt ($curl, Curlopt_post, true); curl_setopt ($curl, Curlopt_postfields, $post _data); curl_setopt ($curl, Curlopt_httpheader, ["Content-type:multipart/form-data; Boundary= ". Static:: $delimiter, "Content-length:". strlen ($post _data)]); $response = curl_exec ($curl); Curl_close ($curl); $info = Json_decode ($response, true); if (!is_array ($info [' msg ')] && $info [' msg '] = = $param [' filesize ']) {$param [' offset '] = $param [' Filesiz E ']; $param [' upload '] = '; return $this->putpart ($param); } return $response; } private static function Builddata ($param) {$data = '; $eol = "\ r \ n"; $upload = $param [' Upload ']; unset ($param [' upload ']); foreach ($param as $name = = $content) {$data. = "-". Static:: $delimiter. "\ r \ n". ' Content-disposition:form-data; Name= "'. $name. "\" \r\n\r\n ". $content. "\ r \ n"; }//splicing file stream $data. = "--". Static:: $delimiter. $eol. ' Content-disposition:form-data; Name= "Upload"; Filename= "'. $param [' filename ']. ‘"‘ . " \ r \ n ". ' Content-type:application/octet-stream '. " \r\n\r\n "; $data. = $upload. "\ r \ n"; $data. = "--". Static:: $delimiter. "--\r\n"; return $data; public static function getinstance () {if (!static:: $instance) {static:: $instance = new static (); } return static:: $instance; }}
How to use
$fields = array( ‘type‘ => ‘video‘, ‘filename‘ => ‘1407.png‘, ‘filesize‘ => 58701, ‘offset‘ => 0, ‘filetype‘ => ‘.acc‘, ‘originName‘ => ‘1407.png‘, ‘upload‘=>file_get_contents(‘0407.png‘));$part = UploadPart::getInstance()->putPart($fields);
Uploading a file stream in PHP with Multipart/form-data