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?

  1. <?php
  2. //get unique id
  3. $up_id = uniqid();
  4. ?>
  5.  
  6. <?php
  7.  
  8. //process the forms and upload the files
  9. if (isset($_POST['Submit'])) {
  10.  
  11. //specify folder for file upload
  12. $folder = "";
  13.  
  14. //specify redirect URL
  15. $redirect = "upload.php?success";
  16.  
  17. //upload the file
  18. move_uploaded_file($_FILES["file"]["tmp_name"], $folder.$_FILES["file"]["name"]);
  19.  
  20. //do whatever else needs to be done (insert information into database, etc...)
  21.  
  22. //redirect user
  23. header('Location: '.$redirect); die;
  24. }
  25.  
  26. //
  27.  
  28. ?>
  29.  
  30. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  31. <html xmlns="http://www.w3.org/1999/xhtml">
  32. <head>
  33. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  34. <title>Upload your file</title>
  35.  
  36. <!--Progress Bar and iframe Styling-->
  37. <link href="style_progress.css" rel="stylesheet" type="text/css" />
  38.  
  39. <!--Get jQuery-->
  40. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
  41. <!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script> -->
  42.  
  43. <!--display bar only if file is chosen-->
  44. <script>
  45.  
  46. $(document).ready(function() {
  47. //
  48.  
  49. //show the progress bar only if a file field was clicked
  50. var show_bar = 0;
  51. $('input[type="file"]').click(function(){
  52. show_bar = 1;
  53. });
  54.  
  55. //show iframe on form submit
  56. $("#form1").submit(function(){
  57.  
  58. if (show_bar == 1) {
  59. $('#upload_frame').show();
  60. function set () {
  61. $('#upload_frame').attr('src','upload_frame.php?up_id=<?php echo $up_id; ?>');
  62. }
  63. setTimeout(set);
  64. }
  65. });
  66. //
  67.  
  68. });
  69.  
  70. </script>
  71.  
  72. </head>
  73.  
  74. <body>
  75. <h1>Upload your file </h1>
  76.  
  77. <div>
  78. <?php if (isset($_GET['success'])) { ?>
  79. <span class="notice">Your file has been uploaded.</span>
  80. <?php } ?>
  81. <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  82. Choose a file to upload<br />
  83.  
  84. <!--APC hidden field-->
  85. <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
  86. <!---->
  87.  
  88. <input name="file" type="file" id="file" size="30"/>
  89.  
  90. <!--Include the iframe-->
  91. <br />
  92. <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
  93. <br />
  94. <!---->
  95.  
  96. <input name="Submit" type="submit" id="submit" value="Submit" />
  97. </form>
  98. </div>
  99.  
  100. </body>
  101.  
  102. </html>
  103.  


style

  1. /*iframe*/
  2. #upload_frame {
  3. border:0px;
  4. height:40px;
  5. width:400px;
  6. display:block;
  7. }
  8.  
  9. #progress_container {
  10. width: 300px;
  11. height: 30px;
  12. border: 1px solid #CCCCCC;
  13. background-color:#EBEBEB;
  14. display: block;
  15. margin:5px 0px -15px 0px;
  16. }
  17.  
  18. #progress_bar {
  19. position: relative;
  20. height: 30px;
  21. background-color: #F3631C;
  22. width: 0%;
  23. z-index:10;
  24. }
  25.  
  26. #progress_completed {
  27. font-size:16px;
  28. z-index:40;
  29. line-height:30px;
  30. padding-left:4px;
  31. color:#FFFFFF;
  32. }
  33.  


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.