From 28a441d1f314d524846f9226d277017f0548463b Mon Sep 17 00:00:00 2001 From: xevidos Date: Thu, 12 Dec 2019 08:22:43 -0500 Subject: [PATCH] Added ini get setting functions, Continued work on new Upload system --- components/filemanager/class.filemanager.php | 6 +- components/filemanager/init.js | 69 +++++++++++++++++--- components/system/controller.php | 56 ++++++++++++---- js/system.js | 39 +++++++++++ 4 files changed, 147 insertions(+), 23 deletions(-) diff --git a/components/filemanager/class.filemanager.php b/components/filemanager/class.filemanager.php index a3175a8..b3f3a81 100755 --- a/components/filemanager/class.filemanager.php +++ b/components/filemanager/class.filemanager.php @@ -765,7 +765,11 @@ class Filemanager extends Common { mkdir( $dirname, 0755, true ); } - $status = file_put_contents( $path, $blob, FILE_APPEND ); + $handle = fopen( $path, "a" ); + $status = fwrite( $handle, $blob ); + fclose( $handle ); + + //$status = file_put_contents( $path, $blob, FILE_APPEND ); if( $status === false ) { diff --git a/components/filemanager/init.js b/components/filemanager/init.js index 56807c8..5d2fa66 100755 --- a/components/filemanager/init.js +++ b/components/filemanager/init.js @@ -18,6 +18,7 @@ clipboard: '', controller: 'components/filemanager/controller.php', dialog: 'components/filemanager/dialog.php', + post_max_size: ( 1024*1024 ), preview: null, refresh_interval: null, @@ -110,6 +111,35 @@ e.stopPropagation(); codiad.filemanager.upload_drop( e ); }); + + + ( async function( global, $ ) { + + let _this = codiad.filemanager; + let result = await codiad.system.get_ini_setting( 'post_max_size' ); + result = result.toLowerCase() + + console.log( result, result.includes( 'g' ), result.includes( 'm' ), result.includes( 'k' ) ); + + if( result.includes( 'g' ) ) { + + let integer = result.replace( /\D/g, '' ); + + console.log( integer, 1024*1024*1024*integer ); + result = 1024*1024*1024*integer; + } else if( result.includes( 'm' ) ) { + + let integer = result.replace( /^\D+/g, '' ); + result = 1024*1024*integer; + } else if( result.includes( 'k' ) ) { + + let integer = result.replace( /^\D+/g, '' ); + result = 1024*integer; + } + + _this.post_max_size = result; + console.log( _this.post_max_size ); + })( this, jQuery ); }, ////////////////////////////////////////////////////////////////// @@ -1687,18 +1717,37 @@ console.log( file, path ); let _this = codiad.filemanager; - let blob_size = 1024*1024; + let blob_size = 0; let total_size = file.size; + let current = 0; + let reader = new FileReader(); + let blob = null + let upload_status = null; + let total_blobs = 0; - if( total_size < blob_size ) { + if( _this.post_max_size > ( 1024*1024*8 ) ) { - blob_size = total_size; + blob_size = ( 1024*1024*8 ); + } else { + + blob_size = _this.post_max_size; } - let current = start + blob_size; - let reader = new FileReader(); - let blob = file.slice( current, current + blob_size ); - let upload_status = null; + console.log( total_size, blob_size, ( total_size / blob_size ) ); + + if( total_size <= blob_size ) { + + blob_size = total_size; + current = start + blob_size; + blob = file; + } else { + + total_blobs = ( Math.round( ( total_size / blob_size ) ) ); + current = start + blob_size; + blob = file.slice( current, current + blob_size ); + } + + console.log( current, blob_size, total_blobs ); if( status === null ) { @@ -1721,7 +1770,11 @@ if( result.bytes > 0 && current <= total_size ) { status.text( ( ( current / total_size )*100 ).toFixed( 2 ) + '%' ); - _this.upload_blobs( file, path, current, status ); + + if( current < total_size ) { + + _this.upload_blobs( file, path, current, status ); + } } } catch( exception ) { diff --git a/components/system/controller.php b/components/system/controller.php index 85f1a98..fd8bdc3 100644 --- a/components/system/controller.php +++ b/components/system/controller.php @@ -1,9 +1,18 @@ create_default_tables(); - - //echo var_dump( $result ); - - if( $result === true ) { + if( is_admin() ) { - exit( formatJSEND( "success", "Created tables." ) ); + global $sql; + $result = $sql->create_default_tables(); + + //echo var_dump( $result ); + + if( $result === true ) { + + exit( formatJSEND( "success", "Created tables." ) ); + } else { + + exit( formatJSEND( "error", array( "message" => "Could not create tables.", "result" => $result ) ) ); + } } else { - exit( formatJSEND( "error", array( "message" => "Could not create tables.", "result" => $result ) ) ); + exit( formatJSEND( "error", "Only admins can use this method." ) ); } - } else { + break; + + case( "get_ini_setting" ): - exit( formatJSEND( "error", "Only admins can use this method." ) ); - } + if( isset( $_POST["option"] ) ) { + + $option = $_POST["option"]; + } else { + + $option = $_GET["option"]; + } + + exit( json_encode( array( + "option" => $option, + "value" => ini_get( $option ), + ))); + break; } \ No newline at end of file diff --git a/js/system.js b/js/system.js index ebde2e3..e786ecd 100755 --- a/js/system.js +++ b/js/system.js @@ -149,6 +149,45 @@ }, }); }, + + get_ini_setting: async function( option ) { + + let i = null; + let result = await jQuery.ajax({ + + url: this.controller, + type: "POST", + dataType: 'html', + data: { + action: 'get_ini_setting', + option: option, + }, + success: function( data ) { + + console.log( data ); + }, + error: function(jqXHR, textStatus, errorThrown) { + + codiad.message.error( i18n( 'Error Creating Default Tables' ) ); + console.log('jqXHR:'); + console.log(jqXHR); + console.log('textStatus:'); + console.log(textStatus); + console.log('errorThrown:'); + console.log(errorThrown); + }, + }); + + try { + + let data = JSON.parse( result ); + i = data.value; + } catch( e ) { + + console.log( e, result ); + } + return i; + } }; })(this, jQuery);