Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Postęp umieszczania pliku.
Balon93
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 18.03.2007

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


Ściągłem taki uploader Simple Upload PHP Script.
I che w nim zrobić tak aby był postęp umieszczania plików pokazany w procentach.
I może ile jeszcze pozostało czasu (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) (nie koniecznie)
Oto kod:
  1. <?php
  2.  
  3. $site_name = $_SERVER['HTTP_HOST'];
  4. $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
  5. $url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
  6.  
  7. $upload_dir = "upload_files/";
  8. $upload_url = $url_dir."/upload_files/";
  9. $message ="";
  10.  
  11. //create upload_files directory if not exist
  12. //If it does not work, create on your own and change permission.
  13. if (!is_dir("upload_files")) {
  14. die ("upload_files directory doesn't exist");
  15. }
  16.  
  17. if ($_FILES['userfile']) {
  18. $message = do_upload($upload_dir, $upload_url);
  19. }
  20. else {
  21. $message = "";
  22. }
  23.  
  24. print $message;
  25.  
  26. function do_upload($upload_dir, $upload_url) {
  27.  
  28. $temp_name = $_FILES['userfile']['tmp_name'];
  29. $file_name = $_FILES['userfile']['name']; 
  30. $file_type = $_FILES['userfile']['type']; 
  31. $file_size = $_FILES['userfile']['size']; 
  32. $result = $_FILES['userfile']['error'];
  33. $file_url = $upload_url.$file_name;
  34. $file_path = $upload_dir.$file_name;
  35.  
  36. //File Name Check
  37. if ( $file_name =="") { 
  38. $message = "";
  39. return $message;
  40. }
  41. //File Size Check
  42. else if ( $file_size > 5242880) {
  43. $message = "Plik nie został umieszczony na serwerze. Przekroczył limit 5MB.";
  44. return $message;
  45. }
  46. //File Type Check
  47. else if ( $file_type == "text/plain" ) {
  48. $message = "Przepraszam, nie możesz załadować pliku." ;
  49. return $message;
  50. }
  51.  
  52. $result = move_uploaded_file($temp_name, $file_path);
  53. $message = ($result)?"Adres pliku: <a href=$file_url>$file_url</a>" :
  54. "Somthing is wrong with uploading a file.";
  55.  
  56. return $message;
  57. }
  58. ?>
  59. <form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
  60. <p>Podaj adres pliku:
  61. <input type="file" id="userfile" name="userfile">
  62. <input type="submit" name="Umieść!" value="Upload">
  63. </p>
  64. <h5>Uplauder ten stworzyłem dla własnego użytku. <br />
  65. Licz się z tym, że jeżeli umieszczasz tutaj plik bez mojej zgody możesz go stracić.</h5> 
  66. </p>
  67. </form>



-------------------------
poprawiłem tytuł
~Cienki1980


Ten post edytował Cienki1980 19.03.2007, 07:19:56
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
marcini82
post
Post #2





Grupa: Zarejestrowani
Postów: 190
Pomógł: 1
Dołączył: 20.05.2005
Skąd: Poznań

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


Takie rzeczy to mozna zrobic chyba tylko ze specjalnie spatchowana wersja php. Ale jak znajdziesz jakies ciekawe rozwiazanie to napisz...
Go to the top of the page
+Quote Post

Posty w temacie


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: 21.10.2025 - 14:26