我正在創建文件上傳與顯示進度條和關閉按鈕,但這些代碼有一些主要問題。它顯示繼續進度條。主要問題是它刪除該文件,但後刷新頁面,我的所有上傳的文件不可見我從中刪除一些文件。 我只是想創造者文件下載如Gmail一樣提供了多個文件附件的工具同時進度條和關閉按鈕爲由用戶錯誤上傳的文件。上傳文件與進度條和刪除選項在php
<script>
$(document).ready(function() {
$('#photoimg').die('click').live('change', function()
{
//$("#preview").html('');
$("#imageform").ajaxForm({target: '#preview',
beforeSubmit:function(){
console.log('ttest');
$("#imageloadstatus").show();
$("#imageloadbutton").hide();
},
success:function(){
console.log('test');
$("#imageloadstatus").hide();
$("#imageloadbutton").show();
},
error:function(){
console.log('xtest');
$("#imageloadstatus").hide();
$("#imageloadbutton").show();
} }).submit();
});
});
</script>
<div class="wrap">
<?php
/**
* Multi file upload example
* @author Resalat Haque
* @link http://www.w3bees.com/2013/02/multiple-file-upload-with-php.html
**/
if(isset($_POST['submit']))
{
$valid_formats = array("jpg", "png", "gif", "zip", "bmp","doc","docx");
$max_file_size = 1024*100; //100 kb
$path = "uploads/"; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to execute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif(! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats)){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name)) {
$path="uploads/".$name;
?>
<div id='imageloadstatus' style='display:none'></div>
<div id='imageloadbutton'>
<script type="text/javascript">
<?php
echo "<a href=\"dl.php?file=".$name."\">".$name."</a> <a href=\"dl.php?file=".$name."\" > <img src='image/loader.gif' alt='Uploading....'/><img src=\"image/close.jpg\" /></a><br />";
$count++; // Number of successfully uploaded files
}
}
}
}
}
?>
<?php
# error messages
if (isset($message)) {
foreach ($message as $msg) {
printf("<p class='status'>%s</p></ br>\n", $msg);
}
}
# success message
if($count !=0){
printf("<p class='status'>%d files added successfully!</p>\n", $count);
}
?>
<br />
<?php } ?>
<!doctype html>
<html lang="en">
<head>
<style type="text/css">
/* Style goes here */
</style>
</head>
<body>
<!-- Multiple file upload html form-->
<form action="upload_demo.php" method="post" enctype="multipart/form-data" id="imageform">
<div id='preview'>
</div>
<input type="file" name="files[]" multiple="multiple" id="photoimg">
<input type="submit" value="Upload" name='submit'>
</form>
</div>
</body>
</html>
要刪除的文件dl.php
<?php if(isset($_GET['file']))
{
$file=$_GET['file'];
$path="uploads/".$file;
unlink($path);
// echo "The file: ".$file." has been deleted.";
?>
<script> window.location.href = "upload_demo.php";
</script>
<?php
} ?>
你想要這樣的行爲嗎? http://www.uploadify.com/demos/ –
雅但文件上傳與doc,pdf和圖像文件像jpg,jpeg,png格式 – user3300358
看看文檔[here](http://www.uploadify的.com /文檔/ uploadify/filetypeexts /)。你可以指定你想要的擴展名。 –