Added ini get setting functions, Continued work on new Upload system

This commit is contained in:
xevidos 2019-12-12 08:22:43 -05:00
parent 4221ef34ba
commit 28a441d1f3
4 changed files with 147 additions and 23 deletions

View File

@ -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 ) {

View File

@ -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 ) {

View File

@ -1,9 +1,18 @@
<?php
require_once('../../common.php');
if ( ! isset( $_POST['action'] ) ) {
if ( ! isset( $_POST['action'] ) && ! isset( $_GET['action'] ) ) {
die( formatJSEND( "error", "Missing parameter" ) );
} else {
if( isset( $_POST["action"] ) ) {
$action = $_POST["action"];
} else {
$action = $_GET["action"];
}
}
//////////////////////////////////////////////////////////////////
@ -12,24 +21,43 @@ if ( ! isset( $_POST['action'] ) ) {
checkSession();
if ( $_POST['action'] == 'create_default_tables' ) {
switch( $action ) {
if( is_admin() ) {
case( "create_default_tables" ):
global $sql;
$result = $sql->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;
}

View File

@ -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);