Chciałbym zaimplementować od swojej aplikacji uplaoder ze strony http://www.johnboy.com/php-upload-progress-bar/ jest do dość łatwe a pasek działa bez problemów. jeśli zauważycie w demo to jak plik zostanie wysłany aplikacja wraca do położenia początkowego. A ja bym chciał aby po wysłaniu pliku przeszła do innej strony czy też ustawiła coś w zmiennej sesyjnej lub wyświetlenie napisu i nie odświeżania strony. Ale gdzie to zmienić? Nie widzę tu żadnego refresh'a jeśli nawet dopisze kod za napisami:
  1. //do whatever else needs to be done (insert information into database, etc...)

to owszem kod się wykona ale mimo wszystko stronka wraca do pozycji startowej czego ja bym nie chciał. Proszę o pomoc w tej sprawie.
Aby było łatwiej to wrzucam pliki z kodem:
plik -upload.php
  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($_FILES["file"])) {
  10.  
  11. //specify folder for file upload
  12. $folder = "../Files/";
  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. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  30. <html xmlns="http://www.w3.org/1999/xhtml">
  31. <head>
  32. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  33. <title>Upload your file</title>
  34.  
  35. <!--Progress Bar and iframe Styling-->
  36. <link href="style_progress.css" rel="stylesheet" type="text/css" />
  37.  
  38. <!--Get jQuery-->
  39. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
  40.  
  41. <!--display bar only if file is chosen-->
  42. <script>
  43.  
  44. $(document).ready(function() {
  45. //
  46.  
  47. //show the progress bar only if a file field was clicked
  48. var show_bar = 0;
  49. $('input[type="file"]').click(function(){
  50. show_bar = 1;
  51. });
  52.  
  53. //show iframe on form submit
  54. $("#form1").submit(function(){
  55.  
  56. if (show_bar === 1) {
  57. $('#upload_frame').show();
  58. function set () {
  59. $('#upload_frame').attr('src','./upload_new/upload_frame.php?up_id=<?php echo $up_id; ?>');
  60. }
  61. setTimeout(set);
  62. }
  63. });
  64. //
  65.  
  66. });
  67.  
  68. </script>
  69.  
  70. </head>
  71.  
  72. <body>
  73. <h1>Upload your file </h1>
  74.  
  75. <div>
  76. <?php if (isset($_GET['success'])) { ?>
  77. <span class="notice">Your file has been uploaded.</span>
  78. <?php } ?>
  79. <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  80.  
  81. Choose a file to upload<br />
  82.  
  83. <!--APC hidden field type="hidden"-->
  84. <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
  85. <!---->
  86.  
  87. <input name="file" type="file" id="file" size="30"/>
  88.  
  89. <!--Include the iframe-->
  90. <br />
  91. <iframe id="upload_frame" name="upload_frame" > </iframe>
  92.  
  93. <br />
  94. <!-- frameborder="0" border="0" src="" scrolling="no" scrollbar="no"-->
  95.  
  96. <input name="Submit" type="submit" id="submit" value="Submit" />
  97. </form>
  98. </div>
  99.  
  100. </body>
  101.  
  102. </html>


plik- upload_frame.php
  1. <?php
  2.  
  3. $url = basename($_SERVER['SCRIPT_FILENAME']);
  4.  
  5. //Get file upload progress information.
  6. if(isset($_GET['progress_key'])) {
  7. $status = apc_fetch('upload_'.$_GET['progress_key']);
  8. echo $status['current']/$status['total']*100;
  9. die;
  10. }
  11.  
  12. //
  13.  
  14. ?>
  15.  
  16. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
  17. <link href="style_progress.css" rel="stylesheet" type="text/css" />
  18.  
  19. <script>
  20. $(document).ready(function() {
  21. //
  22.  
  23. setInterval(function()
  24. {
  25. $.get("<?php echo $url; ?>?progress_key=<?php echo $_GET['up_id']; ?>&randval="+ Math.random(), {
  26. //get request to the current URL (upload_frame.php) which calls the code at the top of the page. It checks the file's progress based on the file id "progress_key=" and returns the value with the function below:
  27. },
  28. function(data) //return information back from jQuery's get request
  29. {
  30. $('#progress_container').fadeIn(100); //fade in progress bar
  31. $('#progress_bar').width(data +"%"); //set width of progress bar based on the $status value (set at the top of this page)
  32. $('#progress_completed').html(parseInt(data) +"%"); //display the % completed within the progress bar
  33. }
  34. )},500); //Interval is set at 500 milliseconds (the progress bar will refresh every .5 seconds)
  35.  
  36. });
  37.  
  38.  
  39. </script>
  40.  
  41. <body style="margin:0px">
  42. <!--Progress bar divs-->
  43. <div id="progress_container">
  44. <div id="progress_bar">
  45. <div id="progress_completed"></div>
  46. </div>
  47. </div>
  48. <!---->
  49. </body>
  50.  
  51.  
  52. <?php
  53. /*
  54.  * Server Requirements
  55.  
  56.   * PHP 5.2 or greater
  57.  
  58.   * APC
  59.   Make sure you have APC installed on your server. It won't work without it. It's easy to install, so if you don't have root acces to your server, ask your hosting provider to take care of it for you.
  60.   Installation instructions: Linux | Windows
  61.  
  62.   Important: Make sure to include apc.rfc1867 = on in your php.ini file after APC is installed. Your php.ini file should be located at /etc/php.ini.
  63. */
  64. ?>