500000 && $status['current']/$status['total'] < 0.9 ) { // Large file and we are < 90% complete $status['interval'] = 3000; } else if($status['total'] > 200000 && $status['current']/$status['total'] < 0.8 ) { // Is this a largeish file and we are < 80% complete $status['interval'] = 2000; } else { $status['interval'] = 1000; } owupload_output($status); } else { $status = array(); $status['noprogress'] = true; foreach($owupload_allowed_extensions as $e) { if(file_exists(OWUPLOAD_PATH.'/'.$check.'.'.$e)) { $ext = $e; break; } } if($ext) { $status['url'] = owupload_file_uri($check.'.'.$ext); } owupload_output($status); } } // Display error function owupload_error($msg) { echo owupload_output(array('error' => $msg)); } function owupload_output($status, $showLoadingMsg = false) { $script = ' try { '.(($_SERVER['REQUEST_METHOD']=='POST') ? 'top.' : '').'owUploadButton.statusCb('.json_encode($status).'); } catch(e) { alert(e.message); } '; if($_SERVER['REQUEST_METHOD']=='POST') { echo ''; } else { echo $script; } if($_SERVER['REQUEST_METHOD']=='POST' && $showLoadingMsg) { echo <<
Upload en cours...
END; } exit; } function owupload_file_uri($filename) { $path = $_SERVER['PHP_SELF']; $file = basename ($path); if($_SERVER['SERVER_PORT']!=80) $base = str_replace($file,"", $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['SCRIPT_NAME']); else $base = str_replace($file,"", $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']); $base = str_replace('/admin/owEditor/','', $base); //$folder = "http://".$base."/data/images"; // => 127*/.../*images $folder = "../../data/images"; // => 127*/.../*images return $folder.'/'.$filename; } function ini_max_upload_size() { $post_size = ini_get('post_max_size'); $upload_size = ini_get('upload_max_filesize'); if(!$post_size) $post_size = '8M'; if(!$upload_size) $upload_size = '2M'; return min( ini_bytes_from_string($post_size), ini_bytes_from_string($upload_size) ); } function ini_bytes_from_string($val) { $val = trim($val); $last = strtolower($val[strlen($val)-1]); switch($last) { case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } function bytes_to_readable( $bytes ) { if ($bytes<=0) return '0 Byte'; $convention=1000; //[1000->10^x|1024->2^x] $s=array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'); $e=floor(log($bytes,$convention)); return round($bytes/pow($convention,$e),2).' '.$s[$e]; } ?>