惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Help Net Security
Help Net Security
The Hacker News
The Hacker News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
A
Arctic Wolf
T
Tor Project blog
Jina AI
Jina AI
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
Security Latest
Security Latest
Latest news
Latest news
Last Week in AI
Last Week in AI
博客园 - 司徒正美
P
Privacy International News Feed
T
Tenable Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
腾讯CDC
博客园 - 聂微东
Scott Helme
Scott Helme
爱范儿
爱范儿
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
I
Intezer
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 热门话题
有赞技术团队
有赞技术团队
S
Secure Thoughts
WordPress大学
WordPress大学
The Cloudflare Blog
AWS News Blog
AWS News Blog
B
Blog RSS Feed
Cyberwarzone
Cyberwarzone
S
Security Affairs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
L
LINUX DO - 最新话题
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Securelist
S
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - 雪域月光

windows如何查看cpu是否支持aux2指令集 git commit错误 error: bad signature 0x00000000 fatal: index file corrupt git pull时遇到error: cannot lock ref 'xxx': ref xxx is at (一个commitID) but expected的解决办法 git tortoise commit时出错 fatal : unable to read f77cxxxxxxxxxxx git unable to resolve reference 'refs/remotes/gitee/20210825-add-Projet-coreScene': reference broken git如何获取远端仓库新分支 git 清除本地修改 项目添加git忽略文件无效的处理 git tortoise commit 出现 fatal bad revidion head freeswitch 使用info显示的通道变量 freeswitch dialplan 基础 字符编码:Unicode和UTF-8之间的关系 NET(C#):关于正确读取中文编码文件 UTF-8和GBK有什么区别 gb2312,gbk,utf8的区别 PHP的ob_flush()与flush()区别 微信小程序如何实现和微信客服通话? 微信小程序如何接入? 微信小程序和微信公众号的id是一个吗
php+javascript实现的动态显示服务器运行程序进度条功能示例
雪域月光 · 2018-04-24 · via 博客园 - 雪域月光

本文实例讲述了php+javascript实现的动态显示服务器运行程序进度条功能。分享给大家供大家参考,具体如下:

经常有这样的业务要处理,服务器上有较多的业务需要处理,需要分批操作,于是就需要一个提示客户现在完成进度的进度条。

这个是php+javascript的进度条。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

<?php

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

  $users[] = 'Tom_' . $i;

$width = 500;           

$total = count($users);      

$pix = $width / $total;      

$progress = 0;          

?>

<html>

<head>

  <title>动态显示服务器运行程序的进度条</title>

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

  <style>

  body, div input { font-family: Tahoma; font-size: 9pt }

  </style>

  <script language="JavaScript">

  <!--

  function updateProgress(sMsg, iWidth)

  {

    document.getElementById("status").innerHTML = sMsg;

    document.getElementById("progress").style.width = iWidth + "px";

    document.getElementById("percent").innerHTML = parseInt(iWidth / <?php echo $width; ?> * 100) + "%";

   }

  </script>

</head>

<body>

<div style="margin: 4px; padding: 8px; border: 1px solid gray; background: #EAEAEA; width: <?php echo $width+8; ?>px">

  <div><font color="gray">如下进度条的动态效果由服务器端 PHP 程序结合客户端 JavaScript 程序生成。</font></div>

  <div style="padding: 0; border: 1px solid navy; width: <?php echo $width; ?>px">

  <div id="progress" style="padding: 0; border: 0; width: 0px; text-align: center;  height: 16px"></div>

  </div>

  <div id="status"> </div>

  <div id="percent" style="position: relative; top: -30px; text-align: center; font-weight: bold; font-size: 8pt">0%</div>

</div>

<?php

flush(); 

foreach ($users as $user) {

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

    ;;

   }

?>

<script language="JavaScript">

  updateProgress("正在操作用户“<?php echo $user; ?>” ....", <?php echo min($width, intval($progress)); ?>);

</script>

<?php

  flush(); 

  $progress += $pix;

?>

<script language="JavaScript">

  updateProgress("操作完成!", <?php echo $width; ?>);

</script>

<?php

flush();

?>

</body>

</html>

运行效果如下: