Czołem, mam taki skrypt na upload pliku wraz z paskiem postępu, lecz coś mi ten pasek nie działa (nie wyświetla go). Czy jest to prawidłowy skrypt?
<?php
//get unique id
?>
<?php
//process the forms and upload the files
if (isset($_POST['Submit'])) {
//specify folder for file upload
$folder = "";
//specify redirect URL
$redirect = "upload.php?success";
//upload the file
//do whatever else needs to be done (insert information into database, etc...)
//redirect user
}
//
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Upload your file</title>
<!--Progress Bar and iframe Styling-->
<link href="style_progress.css" rel="stylesheet" type="text/css" />
<!--Get jQuery-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script> -->
<!--display bar only if file is chosen-->
<script>
$(document).ready(function() {
//
//show the progress bar only if a file field was clicked
var show_bar = 0;
$('input[type="file"]').click(function(){
show_bar = 1;
});
//show iframe on form submit
$("#form1").submit(function(){
if (show_bar == 1) {
$('#upload_frame').show();
function set () {
$('#upload_frame').attr('src','upload_frame.php?up_id=
<?php echo $up_id; ?>');
}
setTimeout(set);
}
});
//
});
</script>
</head>
<body>
<h1>Upload your file </h1>
<div>
<?php if (isset($_GET['success'])) { ?> <span class="notice">Your file has been uploaded.</span>
<?php } ?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Choose a file to upload<br />
<!--APC hidden field-->
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="
<?php echo $up_id; ?>"/>
<!---->
<input name="file" type="file" id="file" size="30"/>
<!--Include the iframe-->
<br />
<iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
<br />
<!---->
<input name="Submit" type="submit" id="submit" value="Submit" />
</form>
</div>
</body>
</html>
style
/*iframe*/
#upload_frame {
border:0px;
height:40px;
width:400px;
display:block;
}
#progress_container {
width: 300px;
height: 30px;
border: 1px solid #CCCCCC;
background-color:#EBEBEB;
display: block;
margin:5px 0px -15px 0px;
}
#progress_bar {
position: relative;
height: 30px;
background-color: #F3631C;
width: 0%;
z-index:10;
}
#progress_completed {
font-size:16px;
z-index:40;
line-height:30px;
padding-left:4px;
color:#FFFFFF;
}
Jeśli ten skrypt się nie nadaje, to jak zrobić taki pasek postępu?.
Myślałem żeby np co 1 ms sprawdzać ile bajtów z danego pliku znajduje się na serwerze i obliczać na podstawie tego procent.
Może da się jakoś inaczej?, proszę o porady. Nie chciałbym pisać tego we flashu.