protected function uploadChunk($model)
    {
        $result = [
            "code" => 0,
            "message" => "Unknown error."
        ];
        
        $sid = $model->id;
        $model_subfolder = $model->category_id . '/' . $sid;
        $model_tmp_folder = public_path() . '/assets/medias/tmp/' . $model_subfolder;
        $model_folder = public_path() . '/assets/medias/' . $model_subfolder;
        
        $fileName = $this->checkRequest("name", $_FILES["file"]["name"]);
        $filePath = $model_tmp_folder . "/$fileName";
        
        $chunk = $this->checkRequest("chunk");
        $chunks = $this->checkRequest("chunks");
        
        // Create the directory
        $this->checkFolder($model_tmp_folder);

        // Open temp file
        $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
        if ($out) {
            // Read binary input stream and append it to temp file
            $sin = @fopen($_FILES['file']['tmp_name'], "rb");

            if ($sin) {
                while ($buff = fread($sin, 4096)) {
                    fwrite($out, $buff);
                }
            } else {
                $result["message"] = Lang::get('redminportal::messages.upload_error_failed_to_open_input_stream');
                return json_encode($result);
            }

            @fclose($sin);
            @fclose($out);

            @unlink($_FILES['file']['tmp_name']);
        } else {
            $result["message"] = Lang::get('redminportal::messages.upload_error_failed_to_open_output_stream');
            return json_encode($result);
        }

        // Check if file has been uploaded
        if (!$chunks || $chunk == $chunks - 1) {
            // Strip the temp .part suffix off
            rename("{$filePath}.part", $filePath);

            $this->saveMedia($model, $filePath);

            $file = new FileInfo($filePath);
            
            // Delete old media
            $file->deleteFiles($model_folder);

            // Create the directory
            $this->checkFolder($model_folder);

            $file->move($model_folder, $fileName);

            // Delete tmp media
            $file->deleteFiles($model_tmp_folder);
        }
        
        $result["code"] = 1;
        $result["message"] = Lang::get('redminportal::messages.upload_success');
        return json_encode($result);
    }
protected function uploadChunk($model)
    {
        $result = [
            "code" => 0,
            "message" => "Unknown error."
        ];
        
        $sid = $model->id;
        $model_subfolder = $model->category_id . '/' . $sid;
        $model_tmp_folder = public_path() . '/assets/medias/tmp/' . $model_subfolder;
        $model_folder = public_path() . '/assets/medias/' . $model_subfolder;
        
        $fileName = $this->checkRequest("name", $_FILES["file"]["name"]);
        $filePath = $model_tmp_folder . "/$fileName";
        
        $chunk = $this->checkRequest("chunk");
        $chunks = $this->checkRequest("chunks");
        
        // Create the directory
        $this->checkFolder($model_tmp_folder);

        // Open temp file
        $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
        if ($out) {
            // Read binary input stream and append it to temp file
            $sin = @fopen($_FILES['file']['tmp_name'], "rb");

            if ($sin) {
                while ($buff = fread($sin, 4096)) {
                    fwrite($out, $buff);
                }
            } else {
                $result["message"] = Lang::get('redminportal::messages.upload_error_failed_to_open_input_stream');
                return json_encode($result);
            }

            @fclose($sin);
            @fclose($out);

            @unlink($_FILES['file']['tmp_name']);
        } else {
            $result["message"] = Lang::get('redminportal::messages.upload_error_failed_to_open_output_stream');
            return json_encode($result);
        }

        // Check if file has been uploaded
        if (!$chunks || $chunk == $chunks - 1) {
            // Strip the temp .part suffix off
            rename("{$filePath}.part", $filePath);

            $this->saveMedia($model, $filePath);

            $file = new FileInfo($filePath);
            
            // Delete old media
            $file->deleteFiles($model_folder);

            // Create the directory
            $this->checkFolder($model_folder);

            $file->move($model_folder, $fileName);

            // Delete tmp media
            $file->deleteFiles($model_tmp_folder);
        }
        
        $result["code"] = 1;
        $result["message"] = Lang::get('redminportal::messages.upload_success');
        return json_encode($result);
    }
protected function uploadChunk ( $ model ) { $ result = [ "code" => 0 , "message" => "Unknown error." ] ; $ sid = $ model -> id ; $ model_subfolder = $ model -> category_id . '/' . $ sid ; $ model_tmp_folder = public_path ( ) . '/assets/medias/tmp/' . $ model_subfolder ; $ model_folder = public_path ( ) . '/assets/medias/' . $ model_subfolder ; $ fileName = $ this -> checkRequest ( "name" , $ _FILES [ "file" ] [ "name" ] ) ; $ filePath = $ model_tmp_folder . "/$fileName" ; $ chunk = $ this -> checkRequest ( "chunk" ) ; $ chunks = $ this -> checkRequest ( "chunks" ) ; // Create the directory $ this -> checkFolder ( $ model_tmp_folder ) ; // Open temp file $ out = @ fopen ( "{$filePath}.part" , $ chunk == 0 ? "wb" : "ab" ) ; if ( $ out ) { // Read binary input stream and append it to temp file $ sin = @ fopen ( $ _FILES [ 'file' ] [ 'tmp_name' ] , "rb" ) ; if ( $ sin ) { while ( $ buff = fread ( $ sin , 4096 ) ) { fwrite ( $ out , $ buff ) ; } } else { $ result [ "message" ] = Lang :: get ( 'redminportal::messages.upload_error_failed_to_open_input_stream' ) ; return json_encode ( $ result ) ; } @ fclose ( $ sin ) ; @ fclose ( $ out ) ; @ unlink ( $ _FILES [ 'file' ] [ 'tmp_name' ] ) ; } else { $ result [ "message" ] = Lang :: get ( 'redminportal::messages.upload_error_failed_to_open_output_stream' ) ; return json_encode ( $ result ) ; } // Check if file has been uploaded if ( ! $ chunks || $ chunk == $ chunks - 1 ) { // Strip the temp .part suffix off rename ( "{$filePath}.part" , $ filePath ) ; $ this -> saveMedia ( $ model , $ filePath ) ; $ file = new FileInfo ( $ filePath ) ; // Delete old media $ file -> deleteFiles ( $ model_folder ) ; // Create the directory $ this -> checkFolder ( $ model_folder ) ; $ file -> move ( $ model_folder , $ fileName ) ; // Delete tmp media $ file -> deleteFiles ( $ model_tmp_folder ) ; } $ result [ "code" ] = 1 ; $ result [ "message" ] = Lang :: get ( 'redminportal::messages.upload_success' ) ; return json_encode ( $ result ) ; }
Upload file chunk

@param object Media
Upload file chunk