首页 > 代码库 > php文件上传进度条例子
php文件上传进度条例子
<?php session_start(); ?> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title>Demo : PHP(5.4) Upload Progress via Session</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta name="author" content=""> <meta name="robots" content="INDEX,FOLLOW" /> <link rel="shortcut icon" href="http://www.mamicode.com/favicon.ico"> <link href="http://www.mamicode.com/assets/css/bootstrap.min.css" rel="stylesheet"> <link href="http://www.mamicode.com/assets/css/pureweber.css" rel="stylesheet"> <style type="text/css"> .progress{ width:100%; border:1px solid #4da8fe; border-radius:40px; height:20px; position:relative; } .progress .label{ position:relative; text-align:center; } .progress .bar{ position:absolute; left:0;top:0; background:#4D90FE; height:20px; border-radius:40px; min-width:20px; } </style> </head> <body> <div id="nav" class="container"> <div class="inner"> <a href="http://www.mamicode.com/" class="logo">PureWeber</a> <ul> <li><a id="to-top" href="http://www.mamicode.com/#nav">« 回到文章</a></li> </ul> </div> </div> <div id="wrap" class="container"> <div id="header"> <h1>Demo : PHP(5.4) Upload Progress via Session</h1> </div> <div id="article"> <form id="upload-form" action="upload.php" method="POST" enctype="multipart/form-data" style="margin:15px 0" target="hidden_iframe"> <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="http://www.mamicode.com/test" /> <p><input type="file" name="file1" /></p> <p><input type="submit" value="http://www.mamicode.com/Upload" /></p> </form> <div id="progress" class="progress" style="margin-bottom:15px;display:none;"> <div class="bar" style="width:0%;"></div> <div class="label">0%</div> </div> </div> <!-- #article --> <div id="footer"> <p>Copyright © 2012 PureWeber.com</p> </div> </div><!-- #wrap --> <iframe id="hidden_iframe" name="hidden_iframe" src="http://www.mamicode.com/about:blank" style="display:none;"></iframe> <script src="http://www.mamicode.com/jquery-1.11.2.min.js"></script> <script type="text/javascript"> function fetch_progress(){ $.get(‘progress.php‘,{ ‘<?php echo ini_get("session.upload_progress.name"); ?>‘ : ‘test‘}, function(data){ var progress = parseInt(data); $(‘#progress .label‘).html(progress + ‘%‘); $(‘#progress .bar‘).css(‘width‘, progress + ‘%‘); if(progress < 100){ setTimeout(‘fetch_progress()‘, 1000); }else{ $(‘#progress .label‘).html(‘完成!‘); } }, ‘html‘); } $(‘#upload-form‘).submit(function(){ $(‘#progress‘).show(); setTimeout(‘fetch_progress()‘, 1000); }); </script> </body> </html>
<?php session_start(); $i = ini_get(‘session.upload_progress.name‘); $key = ini_get("session.upload_progress.prefix") . $_GET[$i]; if (!empty($_SESSION[$key])) { $current = $_SESSION[$key]["bytes_processed"]; $total = $_SESSION[$key]["content_length"]; echo $current < $total ? ceil($current / $total * 100) : 100; }else{ echo 100; } ?>
<?php if(is_uploaded_file($_FILES[‘file1‘][‘tmp_name‘])){ //unlink($_FILES[‘file1‘][‘tmp_name‘]); move_uploaded_file($_FILES[‘file1‘][‘tmp_name‘], "./{$_FILES[‘file1‘][‘name‘]}"); } ?>
php文件上传进度条例子
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。