Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][APC] Pasek postępu uploadu plików
Forum PHP.pl > Forum > PHP
yarek12
Witam, korzystam z gotowego skryptu do paska postępu upladu plików: http://www.johnboy.com/php-upload-progress-bar/.

Na serwerze wszystkie narzucone zmiany przez owy poradnik zostały zmienione pomyślnie, apc zainstalowane, linijka w php.ini zmieniona, jednak po wysłaniu formularza wyskakuje błąd o zmianie nagłówka header.

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\progress\upload.php:6) in C:\xampp\htdocs\progress\upload.php on line 23

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 ($_POST) {
  10.  
  11. //specify folder for file upload
  12. $folder = "file/";
  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_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. Name<br />
  81. <input name="name" type="text" id="name"/>
  82. <br />
  83. <br />
  84. Your email address <br />
  85. <input name="email" type="text" id="email" size="35" />
  86. <br />
  87. <br />
  88. Choose a file to upload<br />
  89.  
  90. <!--APC hidden field-->
  91. <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
  92. <!---->
  93.  
  94. <input name="file" type="file" id="file" size="30"/>
  95.  
  96. <!--Include the iframe-->
  97. <br />
  98. <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
  99. <br />
  100. <!---->
  101.  
  102. <input name="Submit" type="submit" id="submit" value="Submit" />
  103. </form>
  104. </div>
  105.  
  106. </body>
  107.  
  108. </html>
  109.  


Lina 6:

  1. <?php


Linia 23:

  1. header('Location: '.$redirect); die;


Nie mam pojęcia dlaczego występuję problem ze zmianą nagłówka skoro nie został wyżej ustalony.
Z góry dziękuje za pomoc, poradę.
cezet
Nagłówek wysyłasz już w piątej linijce.
Jakakolwiek treść puszczona na wyjście (w tym przypadku linijka między jednym blokiem <?php ?> a drugim <?php ?>)
Dlaczego to rozdzieliłeś? Spróbuj z tego rozdzielenia zrezygnować, a nagłówek się nie wyśle, i będziesz mógł użyć header
cojack
http://www.ultramegatech.com/blog/2008/12/...ogress-bar-php/

masz tu dobry przykład.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.