Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Skrypt Uploadu, File Type Check - Jak skonfigurować?
sofermo
post 25.04.2014, 19:52:50
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 25.04.2014

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


Witam znalazlem na internecie skrypt do uploadu plikow na stronie www, mianowicie moge uploadowac kazdy rodzaj plików chcialbym ustawic tylko do .rar, .zip, 7z czyli same archiwa.

o to skrypt prosze o pomoc :

  1. <center><a href='https://ssl.homepay.pl/stawki-prowizji/' target='_blank' title='płatności internetowe, płatności sms premium'><img src='https://ssl.homepay.pl/files/img/logo_na_tle.png' style='border:0' alt='Logo Homepay' title='Logo Homepay' width='209' height='40' /></a> </center>
  2. <br>
  3. <div id="topbar" class="wrap">
  4. <center>
  5. <div id="topbarleft">
  6. <a href="http://mmocenter.org/upload/"><img src="grafika/logo.jpg" width="450" height="267" alt="" /></a> </center>
  7. </div>
  8. <div id="topbarright">
  9. <link rel="stylesheet" type="text/css" href="grafika/style.css" />
  10. <br>
  11. <?php
  12.  
  13.  
  14.  
  15. $site_name = $_SERVER['HTTP_HOST'];
  16. $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
  17. $url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
  18.  
  19. $upload_dir = "files/";
  20. $upload_url = $url_dir."/files/";
  21. $message ="MMOCenter Upload";
  22.  
  23.  
  24.  
  25.  
  26. //create upload_files directory if not exist
  27. //If it does not work, create on your own and change permission.
  28. if (!is_dir("files")) {
  29. die ("upload_files directory doesn't exist");
  30. }
  31.  
  32. if ($_FILES['userfile']) {
  33. $message = do_upload($upload_dir, $upload_url);
  34. }
  35. else {
  36. $message = "<b><center>MMOCenter Upload</b></center>";
  37. }
  38.  
  39. print $message;
  40.  
  41. function do_upload($upload_dir, $upload_url) {
  42.  
  43. $temp_name = $_FILES['userfile']['tmp_name'];
  44. $file_name = uniqid();
  45. $file_type = $_FILES['userfile']['type'];
  46. $file_size = $_FILES['userfile']['size'];
  47. $result = $_FILES['userfile']['error'];
  48. $file_url = $upload_url.$file_name;
  49. $file_path = $upload_dir.$file_name;
  50.  
  51. //File Name Check
  52. if ( $file_name =="") {
  53. $message = "Nieprawidłowe nazwy pliku";
  54. return $message;
  55. }
  56. //File Size Check
  57. else if ( $file_size > 5000000000) {
  58. $message = "Za duzy plik rozmiar przekroczył 500MB!.";
  59. return $message;
  60. }
  61. //File Type Check
  62. else if ( $file_type == ".exe" ) {
  63. $message = "ERROR! Format pliku ktory chcesz wrzucic jest zakazany!" ;
  64. return $message;
  65. }
  66.  
  67. $result = move_uploaded_file($temp_name, $file_path);
  68. $message = ($result)?"
  69.  
  70.  
  71.  
  72.  
  73. </textarea></form>
  74. <center><h3>Plik został przesłany, skopiuj wygenerowany link.</h3><center/>
  75. <br>
  76. <a href=$file_url>$file_url</a>" :
  77. "Somthing is wrong with uploading a file.";
  78.  
  79. return $message;
  80. }
  81. ?>
  82. <br>
  83. <br>
  84. <form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
  85. <center><b>Wybierz plik : <input type="file" id="userfile" name="userfile"><br>
  86. <br><input type="image" src="grafika/upload.jpg" style="border=0">
  87. </form>
Go to the top of the page
+Quote Post
ZaXaZ
post 25.04.2014, 20:09:49
Post #2





Grupa: Zarejestrowani
Postów: 285
Pomógł: 18
Dołączył: 30.01.2014
Skąd: <?=$_GET['city']?>

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


podmień linijke 62 na to:
else if ($file_type!='.zip' && $file_type!='.rar'){

edit: zapomniałem dodać kropkę do rozszerzen.

ps. napisz czy działa.

Ten post edytował ZaXaZ 25.04.2014, 20:20:26


--------------------
Go to the top of the page
+Quote Post
sofermo
post 25.04.2014, 22:01:14
Post #3





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 25.04.2014

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


  1. <center><a href='https://ssl.homepay.pl/stawki-prowizji/' target='_blank' title='płatności internetowe, płatności sms premium'><img src='https://ssl.homepay.pl/files/img/logo_na_tle.png' style='border:0' alt='Logo Homepay' title='Logo Homepay' width='209' height='40' /></a> </center>
  2. <br>
  3. <div id="topbar" class="wrap">
  4. <center>
  5. <div id="topbarleft">
  6. <a href="http://mmocenter.org/upload/"><img src="grafika/logo.jpg" width="450" height="267" alt="" /></a> </center>
  7. </div>
  8. <div id="topbarright">
  9. <link rel="stylesheet" type="text/css" href="grafika/style.css" />
  10. <br>
  11. <?php
  12.  
  13.  
  14.  
  15. $site_name = $_SERVER['HTTP_HOST'];
  16. $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
  17. $url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
  18.  
  19. $upload_dir = "files/";
  20. $upload_url = $url_dir."/files/";
  21. $message ="MMOCenter Upload";
  22.  
  23.  
  24.  
  25.  
  26. //create upload_files directory if not exist
  27. //If it does not work, create on your own and change permission.
  28. if (!is_dir("files")) {
  29. die ("upload_files directory doesn't exist");
  30. }
  31.  
  32. if ($_FILES['userfile']) {
  33. $message = do_upload($upload_dir, $upload_url);
  34. }
  35. else {
  36. $message = "<b><center>MMOCenter Upload</b></center>";
  37. }
  38.  
  39. print $message;
  40.  
  41. function do_upload($upload_dir, $upload_url) {
  42.  
  43. $temp_name = $_FILES['userfile']['tmp_name'];
  44. $file_name = uniqid();
  45. $file_type = $_FILES['userfile']['type'];
  46. $file_size = $_FILES['userfile']['size'];
  47. $result = $_FILES['userfile']['error'];
  48. $file_url = $upload_url.$file_name;
  49. $file_path = $upload_dir.$file_name;
  50.  
  51. //File Name Check
  52. if ( $file_name =="") {
  53. $message = "Nieprawidłowe nazwy pliku";
  54. return $message;
  55. }
  56. //File Size Check
  57. else if ( $file_size > 5000000000) {
  58. $message = "Za duzy plik rozmiar przekroczył 500MB!.";
  59. return $message;
  60. }
  61. //File Type Check
  62. else if ($file_type!='.zip' && $file_type!='.rar') {
  63. $message = "ERROR! Format pliku ktory chcesz wrzucic jest zakazany!" ;
  64. return $message;
  65. }
  66.  
  67. $result = move_uploaded_file($temp_name, $file_path);
  68. $message = ($result)?"
  69.  
  70.  
  71.  
  72.  
  73. </textarea></form>
  74. <center><h3>Plik został przesłany, skopiuj wygenerowany link.</h3><center/>
  75. <br>
  76. <a href=$file_url>$file_url</a>" :
  77. "Somthing is wrong with uploading a file.";
  78.  
  79. return $message;
  80. }
  81. ?>
  82. <br>
  83. <br>
  84. <form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
  85. <center><b>Wybierz plik : <input type="file" id="userfile" name="userfile"><br>
  86. <br><input type="image" src="grafika/upload.jpg" style="border=0">
  87. </form>


jest tak jak chce dodac zip lub rar to mam

ERROR! Format pliku ktory chcesz wrzucic jest zakazany!


EDIT: NIESTETY NIE DZIALA.

@ UP.

Ten post edytował sofermo 25.04.2014, 20:49:32
Go to the top of the page
+Quote Post
Turson
post 26.04.2014, 09:29:33
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


file['type'] nie wraca rozszerzenia a typ pliku
http://pl.wikipedia.org/wiki/Typ_MIME
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 14.07.2025 - 07:05