|
進度顯示頁代碼
- <?php
- ini_set("memory_limit","120M");
- include("functions.php");
- $dir="image/";
- if ($dh = @opendir($dir)) {
- set_time_limit(0);
- $width = 800; //顯示的進度條長度,單位 px
- $total = count(scandir($dir)); //總共需要操作的記錄數
- $pix = $width / $total; //每條記錄的操作所佔的進度條單位長度
- $progress = 0;
- //echo $totel; //當前進度條長度
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>降低品質</title>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <style>
- body, div input { font-family: Tahoma; font-size: 14px; }
- </style>
- <script language="JavaScript">
- <!--
- function updateProgress(sMsg, iWidth)
- {
- document.getElementById("status").innerHTML = sMsg;
- document.getElementById("progress").style.width = (iWidth-8) + "px";
- document.getElementById("percent").innerHTML = parseInt(iWidth / <?php echo $width; ?> * 100) + "%";
- }
- //-->
- </script>
-
- </head>
- <body>
- <div style="padding: 8px; border:none;left:expression((body.offsetWidth-this.offsetWidth)/2);position:absolute; width: <?php echo $width+8; ?>px" >
- <div><font color="gray">→</font></div>
- <div style="padding:0; margin:3px; background-color: white; border: 1px solid #d6d6d6; width: <?php echo $width; ?>px">
- <div id="progress" style="padding:1px; margin:3px; background: url(bg.gif) center left repeat-x;border:0;width:0px;text-align:center;height:16px"></div>
- </div>
- <div id="status"> </div>
- <div id="percent" style="position: relative; top: -44px; text-align: center; font-weight: bold; font-size:12px; color:#0099ff">0%</div>
- </div>
- <?php
- while (($file = readdir($dh)) !== false) {
- if ($file != "." && $file != "..") {
-
- if(@filetype($dir."/".$file)=="file"){
- $ff=$dir."/".$file;
- quanty($ff);
- }
-
- flush(); //將輸出發送給客戶端瀏覽器
- //foreach ($ff as $user) {
- // 在此處使用空循環模擬較為耗時的操作,實際應用中需將其替換;
- // 如果你的操作不耗時,我想你就沒必要使用這個腳本了 :)
- ?>
- <script language="JavaScript">
- updateProgress("… <?php echo $file; ?> ", <?php echo min($width, intval($progress)); ?>);
- </script>
- <?php
- //flush(); //將輸出發送給客戶端瀏覽器,使其可以立即執行服務器端輸出的 JavaScript 程序。
- $progress += $pix;
- }
-
- }
- //}//end foreach
- // 最後將進度條設置成最大值 $width,同時顯示操作完成
- ?>
- <script language="JavaScript">
- updateProgress("over! ", <?php echo $width; ?>);
- //window.location.href='index.php';
- </script>
- </body>
- </html>
- <?php
- }
- ?>
複製代碼
壓縮圖片函數
- function quanty($filename){
- if(is_file($filename)) {
- $size = getimagesize($filename);
- $fileInfo = pathinfo($filename);
- $ext = strtolower($fileInfo["extension"]);
- $dst_filename = $fileInfo["dirname"]."/".$fileInfo["basename"];
- $max_width = $size[0];
- $max_height = $size[1];
- if($ext == 'jpg' || $ext == 'jpeg'||$ext == 'png'||$ext == 'gif'){
- if ($ext == 'jpg' || $ext == 'jpeg') {
- $src_img = imagecreatefromjpeg($filename) or die( 'Cannot load input JPEG image' );
- } else if ($ext == 'png') {
- $src_img = imagecreatefrompng($filename) or die( 'Cannot load input PNG image' );
- } else if ($ext == 'gif') {
- $src_img = imagecreatefromgif($filename) or die( 'Cannot load input GIF image' );
- }
- $dst_img = imagecreatetruecolor($max_width, $max_height);
- imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $max_width, $max_height, $size[0], $size[1]);
- imagejpeg($dst_img, $dst_filename, 85);
- imagedestroy($src_img);
- imagedestroy($dst_img);
-
- }
- }
- }
複製代碼
|
|