带进度条的PHP和HTML多文件上传

时间:2014-02-07 07:54:19

标签: php html css html5 apc

我有一个网站,允许使用HTML5多重设置上传多个文件。我使用PHP脚本来验证文件并上传它们。仅使用PHP和HTML / CSS我想为正在上传的文件(或文件)创建进度条。我怎样才能做到这一点?我知道PHP可以使用APC来获取文件上传信息,但是如何将这些信息合并到正在上传的多个文件中?

<html>
<head>
<style type="text/css" media="screen">
     div#banner_left {
       position: absolute;
       top: 0%;
       left: 0%;
       width: auto;
     }
     div#banner_right {
       float: right;
       width: auto;
     }
    </style>
<link rel="stylesheet" type="text/css" href="/css/structure.css">
</head>
<?php
echo "<div id='banner_right'>Welcome ";
echo $_SESSION['myusername'];
echo "<br><form action='/logout.php'>";
echo " <input type='submit' value='Logout' style='width:216px; font-size: 15px;'>";
echo "</form>";
echo "</div><br><br>";
?>


<!-- FILE UPLOAD SCRIPT//-->

<?php
if(isset($_POST['submit']))
{
$subject_list = $_POST['subject_list'];
$document_type = $_POST['document_type'];
$uploaddir = "/var/www/rye-high-website/Rye High/uploads/$subject_list/$document_type";
$files=array();
$fdata=$_FILES['rye_file'];
if(is_array($fdata['name'])){
 for($i=0;$i<count($fdata['name']);++$i){
  $files[]=array(
   'name'     => $fdata['name'][$i],
   'tmp_name' => $fdata['tmp_name'][$i],
  );
 }
}
else $files[]=$fdata;

foreach ($files as $file) {
  // uploaded location of file is $file['tmp_name']
  // original filename of file is $file['name']
  $move_file = move_uploaded_file($file['tmp_name'], "$uploaddir/".$file['name']);
}

if ($subject_list == "None") {
   echo '<br><div class="alert">Please Pick A Course Code</div>';
}
if ($document_type == "None"){
   echo  '<br><div class="alert">Please Pick A Document Type</div>';
}
if($move_file){
   echo  '<br><div class="info">File is valid, and was successfully uploaded to: $subject_list folder</div>';
  }
else {
     echo '<br><div class="alert">Upload Failed</div>';
     echo $move_file;
 }
}

?>


<!-- CONTINUE WITH HTTP FORM//-->


<body>
<div id="banner_left">
<img src="/Rye High/images & scripts/logo_ryerson.gif"/>
</div>
<br><br><div class="img">
<img src="/images/logo.png" />
</div><center>
<form enctype="multipart/form-data" action="<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>" method="POST">
Choose Document Type:
<select name="document_type">
<option value="None">Pick Document Type</option>
<option value="Textbooks">Text Books</option>
<option value="Notes & Assignments">Assignment/Notes</option>
</select><br>
Choose Course Code:
<select name="subject_list">
<option value="None">Pick Course</option>
<option value="ACC 100">ACC 100</option>
<option value="ACC 406">ACC 406</option>
</select><br>
Choose file(s) to upload (Max 500MB): <input name="rye_file[]" type="file" id="multiple" multiple />
<input type="submit" name="submit" value="Upload" />
</form>

感谢您的帮助,

P.S。我宁愿避免使用javascript,因为我对它不熟悉。 PHP和HTML / HTML5首选。

1 个答案:

答案 0 :(得分:3)

如果你使用javascript解决问题,你可以省去很多努力! Under是指向教程的链接,可能会从该教程中获得最佳效果,并在Google上搜索。

http://www.w3bees.com/2013/10/file-upload-with-progress-bar.html

http://hayageek.com/jquery-multiple-file-upload/