'err','reason'=>'Data directory not writable'))); else if(!isFolderWritable(ROOT.DS.'tmp')) exit(json_encode(array('status'=>'err','reason'=>'Temp directory not writable'))); $hash = sanatizeString(trim($_REQUEST['hash']))?sanatizeString(trim($_REQUEST['hash'])):false; // check for POST upload if ($_FILES['file']["error"] == UPLOAD_ERR_OK) { //check for duplicates $sha1 = sha1_file($_FILES['file']["tmp_name"]); $hash = sha1Exists($sha1); if($hash) exit(json_encode(array('status'=>'ok','hash'=>$hash,'url'=>URL.$hash))); //get the file type $type = getTypeOfFile($_FILES['file']["tmp_name"]); //cross check filetype for controllers // //image? if(in_array($type,(new ImageController)->getRegisteredExtensions())) { $answer = (new ImageController())->handleUpload($_FILES['file']['tmp_name'],$hash); } //or, a text else if($type=='text') { $answer = (new TextController())->handleUpload($_FILES['file']['tmp_name'],$hash); } //or, a video else if(in_array($type,(new VideoController)->getRegisteredExtensions())) { $answer = (new VideoController())->handleUpload($_FILES['file']['tmp_name'],$hash); } if(!$answer) $answer = array('status'=>'err','reason'=>'Unsupported filetype'); if($answer['hash']) { //add this sha1 to the list addSha1($answer['hash'],$sha1); // Lets' check all storage controllers and tell them that a new file was uploaded $sc = getStorageControllers(); foreach($sc as $contr) { if((new $contr())->isEnabled()===true) (new $contr())->pushFile($answer['hash']); } } echo json_encode($answer); } else exit(json_encode(array('status'=>'err','reason'=>'Upload error')));