filter($_FILES['file']['tmp_name'],'str'); $in = fopen($tmpName, "rb"); if($in) { while($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } fclose($in); fclose($out); @unlink($tmpName); } else { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } } else { // Open temp file $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab"); if($out) { // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); if($in) { while($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } fclose($in); fclose($out); } else { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } } // Check if file has been uploaded if(!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off rename("{$filePath}.part", $filePath); } // rename($targetDir.$fileName,e_MEDIA."images/2012-05/",$fileName); if($_GET['for'] != '') // leave in upload directory if no category given. { $uploadPath = varset($_GET['path'],null); $result = e107::getMedia()->importFile($fileName, $_GET['for'], array('path'=>$uploadPath)); } $log = $_GET; $log['filepath'] = $filePath; $log['filename'] = $fileName; $log['status'] = ($result) ? 'ok' : 'failed'; $type = ($result) ? E_LOG_INFORMATIVE : E_LOG_WARNING; e107::getLog()->add('Media Upload', print_r($log, true), $type, MEDIA_01); $array = array("jsonrpc" => "2.0", "result" => $result, "id" => "id"); echo json_encode($array); // Return JSON-RPC response // die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}'); ?>