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); } $filePath = str_replace('//','/',$filePath); // cleanup . $convertToJpeg = e107::getPref('convert_to_jpeg', 0); $fileSize = filesize($filePath); if(varset($_GET['for']) !== '_icon' && !empty($convertToJpeg)) { if($jpegFile = e107::getMedia()->convertImageToJpeg($filePath, true)) { $filePath = $jpegFile; $fileName = basename($filePath); $fileSize = filesize($jpegFile); } } 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 = e107::getParser()->filter($_GET,'str'); $log['filepath'] = str_replace('../','',$filePath); $log['filename'] = $fileName; $log['filesize'] = $fileSize; $log['status'] = ($result) ? 'ok' : 'failed'; $type = ($result) ? E_LOG_INFORMATIVE : E_LOG_WARNING; e107::getLog()->add('LAN_AL_MEDIA_01', 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"}'); ?>