⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadprogressmeterstatus.class.php

📁 利用ajax准确实现文件上传的进度条显示。
💻 PHP
字号:
<?php

/**
 * Get the status of an in progress upload, 
 *
 * Requires the Upload Progress Meter extension
 */
class UploadProgressMeterStatus {
	/**
	 * Get the status of all uploads passed in
	 */
	function getStatus($ids) {
		$ret = array();
		foreach($ids as $id => $upId) {
			$ret[$id] =  new stdClass();
			
			if (!function_exists('upload_progress_meter_get_info')) {
				$ret[$id]->message = "In Progress";
				$ret[$id]->percent = "10";
				$ret[$id]->noStatus = true;
				return $ret;
			}

			$tmp = upload_progress_meter_get_info($upId);
			if (!is_array($tmp)) {
				sleep(1);
				$tmp = upload_progress_meter_get_info($upId);
				if (!is_array($tmp)) {
					$ret[$id]->message = "Upload Complete";
					$ret[$id]->percent = "100";
					return $ret;
				}
			}

			if ($tmp['bytes_total'] < 1) {
				$percent = 100;
			}
			else {
				$percent = round($tmp['bytes_uploaded'] / $tmp['bytes_total'] * 100, 2);
			}

			if ($percent == 100) {
				$ret[$id]->message = "Complete";
			}

			$eta 		= sprintf("%02d:%02d", $tmp['est_sec'] / 60, $tmp['est_sec'] % 60 );
			$speed 		= $this->_formatBytes($tmp['speed_average']);
			$current 	= $this->_formatBytes($tmp['bytes_uploaded']);
			$total 		= $this->_formatBytes($tmp['bytes_total']);

			$ret[$id]->message = "$eta left (at $speed/sec)	$current/$total($percent%)";
			$ret[$id]->percent = $percent;
		}
		return $ret;
	}

	/**
	 * function to convert bytes to something larger
	 */
	function _formatBytes($x) {
		if ($x < 100)  $x;
		if ($x < 10000)  return sprintf("%.2fKB", $x/1000);
		if ($x < 900000) return sprintf("%dKB", $x/1000);
		return sprintf("%.2fMB", $x/1000/1000);
	}
}
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -