php實現進度條原理

PHP實現進度條的原理:

模版替換,在頁面設置一個標識,輪子自己的頁面,不發請求給服務器,由服務器端獲得進度,然後替換該頁面標識,達到進度條效果。

頁面代碼:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<meta http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT">

<meta http-equiv="Pragma" content="no-cache">

<meta http-equiv="Cache-Control" content="no-cache">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta http-equiv="Lang" content="en">

<meta name="author" content="">

<meta http-equiv="Reply-to" content="@.com">

<meta name="generator" content="PhpED 5.8">

<meta name="description" content="">

<meta name="keywords" content="">

<meta name="creation-date" content="01/01/2009">

<meta name="revisit-after" content="15 days">

<title>進度條</title>

<script type="jquery.min.js"></script>

<script type="text/javascript">

function test(){

location.reload();

setTimeOut('test()',1000)

}

</script>

</head>

<body οnlοad="test()">

<div id="test">0</div>

<div id="" style="width: 100;">{%a%}</div>

</body>

</html>

服務器代碼:

<?php

for($i = 0;$i < 6;$i++){

  echo $i.'&lt;br/&gt;';

  echo str_repeat('      ' ,2024);

  $url = '/t/test.php';

  header("Location: " . $url.'&id='.$i);

  $read_url = realpath('.'.$url);

  $content = file_get_contents('D:/phpnow/htdocs11/design/t/test.php');

 $rr = preg_replace('/{%(.*)%}/','{%'.$i.'%}',$content);

 file_put_contents('D:/phpnow/htdocs11/design/t/test.php',$rr);

  ob_flush();

  flush();

  sleep(1);

}

?>
本文參考地址:https://www.php.cn/php-weizijiaocheng-430019.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章