variables - Restrict Upload on FileSize for FCKeditor PHP -
hi add restriction on uploading image files, on 500kb fck editor.
so in fck edior upload script there included require files:
require('./config.php') ; require('./util.php') ; require('./io.php') ; require('./commands.php') ; require('./phpcompat.php') ;
filesize calcualted in commands.php file , thought take variable (from within function (commands.php) , test see if breaks limit size)
so still in upload.php, have snippet underneath require includes:
$limit_size = 512000; if ( $globals['myfilesize'] >= $limit_size ) { senduploadresults( 1, '', '', ''. $globals['myfilesize'].'' ) ; }
so here function within commands.php file:
function getfoldersandfiles( $resourcetype, $currentfolder ) { global $ifilesize; // map virtual path local server path. $sserverdir = servermapfolder( $resourcetype, $currentfolder, 'getfoldersandfiles' ) ; // arrays hold folders , files names. $afolders = array() ; $afiles = array() ; $ocurrentfolder = @opendir( $sserverdir ) ; if ($ocurrentfolder !== false) { while ( $sfile = readdir( $ocurrentfolder ) ) { if ( $sfile != '.' && $sfile != '..' ) { if ( is_dir( $sserverdir . $sfile ) ) $afolders[] = '<folder name="' . converttoxmlattribute( $sfile ) . '" />' ; else { $ifilesize = @filesize( $sserverdir . $sfile ) ; if ( !$ifilesize ) { $ifilesize = 0 ; $globals['myfilesize'] = $ifilesize; } if ( $ifilesize > 0 ) { $ifilesize = round( $ifilesize / 1024 ) ; if ( $ifilesize < 1 ) $ifilesize = 1 ; global $myfilesize; $globals['myfilesize'] = $ifilesize; } $afiles[] = '<file name="' . converttoxmlattribute( $sfile ) . '" size="' . $ifilesize . '" />' ; } } } closedir( $ocurrentfolder ) ; } // send folders natcasesort( $afolders ) ; echo '<folders>' ; foreach ( $afolders $sfolder ) echo $sfolder ; echo '</folders>' ; // send files natcasesort( $afiles ) ; echo '<files>' ; foreach ( $afiles $sfiles ) echo $sfiles ; echo '</files>' ; }
i approaching right? i'm thinking grab filesize value (i've messed trying make global variable?? ($globals[myfilesize]) , use in if statement see if filesize > limit_size???
thanks
Comments
Post a Comment