Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Upload + Pasek postępu.
moto0095
post
Post #1





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

Ostrzeżenie: (0%)
-----


Witam.
Znalazłem ostatnio skrypt który pokazuje pasek postępu.
I na stronie z przykładem [TUTAJ] jest wszystko ok, jak zrobiłem to na
swojej stronie to w ogóle nie ładuje się plik i nie przesyła.
Nie wiem dlaczego.

KOD:

upload_form.php
  1. <?php $uid = md5(uniqid(rand())); ?>
  2. <html>
  3. <head>
  4. <title>Upload Progess Bar</title>
  5. <style type="text/css">
  6. #pb_outer {
  7. height: 20px;
  8. border: 1px inset #000000;
  9. width: 80%;
  10. margin: 20px auto;
  11. display: none;
  12. }
  13. #pb_inner {
  14. font-weight: bold;
  15. color: #FFFFFF;
  16. background-color: #003399;
  17. height: 20px;
  18. width: 1px;
  19. text-align: center;
  20. }
  21. </style>
  22. <script type="text/javascript">
  23. var HttpRequestObject = false;
  24. if(window.XMLHttpRequest) {
  25. HttpRequestObject = new XMLHttpRequest();
  26. }
  27. else if(window.ActiveXObject) {
  28. HttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  29. }
  30. function startProgress(uid) {
  31. document.getElementById('upload').style.display = 'none';
  32. document.getElementById('pb_outer').style.display = 'block';
  33. setTimeout('getProgress("' + uid + '")', 1000);
  34. }
  35. function getProgress(uid) {
  36. if(HttpRequestObject) {
  37. HttpRequestObject.open('GET', 'getprogress.php?uid=' + uid, true);
  38. HttpRequestObject.onreadystatechange = function() {
  39. if(HttpRequestObject.readyState == 4 && HttpRequestObject.status == 200) {
  40. var progress = HttpRequestObject.responseText;
  41. document.getElementById('pb_inner').style.width = progress + '%';
  42. document.getElementById('pb_inner').innerHTML = progress + '%';
  43. if(progress < 100) {
  44. setTimeout('getProgress("' + uid + '")', 100);
  45. }
  46. else {
  47. document.getElementById('pb_inner').innerHTML = 'Upload Complete!';
  48. }
  49. }
  50. }
  51. HttpRequestObject.send(null);
  52. }
  53. }
  54. </script>
  55. </head>
  56. <body>
  57. <form onSubmit="startProgress('<?php echo $uid; ?>');" action="upload.php" method="post" enctype="multipart/form-data" name="upload" id="upload" target="upload_frame">
  58. <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $uid; ?>" />
  59. <input type="file" name="file" id="file" />
  60. <input type="submit" name="submit" id="submit" value="Upload!" />
  61. </form>
  62. <div id="pb_outer">
  63. <div id="pb_inner"></div>
  64. </div>
  65. <iframe style="display: none" id="upload_frame" name="upload_frame"></iframe>
  66. </body>
  67. </html>



upload.php
  1. <?php
  2. if($_FILES['file']['error'] == UPLOAD_ERR_OK){
  3. $path = '/var/www/uploads/';
  4. $path .= basename($_FILES['file']['name']);
  5. if(move_uploaded_file($_FILES['file']['tmp_name'], $path)){
  6. // upload successful
  7. }
  8. }
  9. ?>


getprogress.php
  1. <?php
  2. header('Expires: Tue, 08 Oct 1991 00:00:00 GMT');
  3. header('Cache-Control: no-cache, must-revalidate');
  4.  
  5. if(isset($_GET['uid'])){
  6. $status = apc_fetch('upload_' . $_GET['uid']);
  7. echo round($status['current']/$status['total']*100);
  8. }
  9. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 10)
luck
post
Post #2





Grupa: Zarejestrowani
Postów: 317
Pomógł: 58
Dołączył: 6.11.2005

Ostrzeżenie: (0%)
-----


Twój kod:
  1. <?php
  2. if($_FILES['file']['error'] == UPLOAD_ERR_OK){
  3. // ciach...
  4. if(move_uploaded_file($_FILES['file']['tmp_name'], $path)){
  5. // upload successful
  6. }
  7. }
  8. ?>
Dlaczego cały czas zakładasz, że wszystko pójdzie ok? Najwyraźniej nie poszło, a Ty nawet nie wyświetlasz błędów, żeby się przekonać co jest nie tak.
Go to the top of the page
+Quote Post
moto0095
post
Post #3





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

Ostrzeżenie: (0%)
-----


To nic nie zmieni.
Coś w kodzie jest nie tak??

Albo, czy zna ktoś (równie prosty jak ten) skrypt pasku postępu (IMG:style_emoticons/default/questionmark.gif) (IMG:style_emoticons/default/questionmark.gif)

Ten post edytował moto0095 15.04.2010, 18:17:25
Go to the top of the page
+Quote Post
rzymek01
post
Post #4





Grupa: Zarejestrowani
Postów: 592
Pomógł: 62
Dołączył: 3.08.2006

Ostrzeżenie: (0%)
-----


a masz zainstalowane rozszerzenie apc?

Ten post edytował rzymek01 15.04.2010, 19:10:53
Go to the top of the page
+Quote Post
moto0095
post
Post #5





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

Ostrzeżenie: (0%)
-----


A jak to sprawdzić (IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
jareeny
post
Post #6





Grupa: Zarejestrowani
Postów: 226
Pomógł: 23
Dołączył: 2.10.2007
Skąd: Słupsk

Ostrzeżenie: (0%)
-----


phpinfo()
Go to the top of the page
+Quote Post
moto0095
post
Post #7





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

Ostrzeżenie: (0%)
-----


Nie wiem czy jest zainstalowany acp nadal:(
Oto link to phpinfo()
http://server17.000webhost.com/phpinfo.php

Ale wydaje mi się że nie (IMG:style_emoticons/default/sad.gif) .
Go to the top of the page
+Quote Post
rzymek01
post
Post #8





Grupa: Zarejestrowani
Postów: 592
Pomógł: 62
Dołączył: 3.08.2006

Ostrzeżenie: (0%)
-----


sam podajesz link do artykułu, z którego zaczęrpnąłeś kod, a nie przeczytałeś go w całości?
na pierwszej stronie jest wszystko powiedziane (http://www.ultramegatech.com/blog/2008/12/creating-upload-progress-bar-php/)
Go to the top of the page
+Quote Post
moto0095
post
Post #9





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

Ostrzeżenie: (0%)
-----


A powiedział by mi ktoś jak zainstalować APC (IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
rzymek01
post
Post #10





Grupa: Zarejestrowani
Postów: 592
Pomógł: 62
Dołączył: 3.08.2006

Ostrzeżenie: (0%)
-----


naprawdę wszystko to już zostało omówione w sieci, zajrzyj sobie do manuala PHP (http://www.php.net/manual/en/apc.installation.php)
Go to the top of the page
+Quote Post
moto0095
post
Post #11





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

Ostrzeżenie: (0%)
-----


Zrezygnowałem jednak z tego.
Ale mam inne pytanie jak mam sobie najprostszy skrypt upladu to jak zrobić tak aby wyświetlił się obrazek ładowania (np: load.gif), ale od razu, bez przeładowania strony?(IMG:style_emoticons/default/questionmark.gif) ?
Albo po prostu ile % pliku się już przesłało bez paska?(IMG:style_emoticons/default/questionmark.gif) ?

Ten post edytował moto0095 16.04.2010, 19:09:42
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 19:55