Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Upload obrazkow
koptus
post
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 7.03.2005

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


Witam, mam mały problem z uploadem obrazków, bazowałem na gotowym rozwiązaniu, jednak coś nie działa i ciągle mam błąd :/
o to kod
  1. <?
  2. if(isset($_POST['submit'])) { //see if submit button is pressed.
  3.  
  4. //check if they decided to upload a pic:
  5. if($_FILES['userfile']['size'] > 1) {
  6.  
  7. $max_size = 10000000000;
  8. $max_height = 300;
  9. $max_width = 300;
  10.  
  11. $info = getimagesize($_FILES['userfile']['tmp_name']);
  12. }
  13. //check file-size (in bytes):    
  14. if(($_FILES['userfile']['size'] > $_POST['MAX_FILE_SIZE']) || ($_FILES['userfile']['size'] > $max_size)) {
  15.    die("<BR><BR>Błąd, rozmiar pliku jest zbyt duży!: (<b>" . $_FILES['userfile']['size'] . "</b>).");
  16. }
  17.  
  18. //check the extension.
  19.     $array = explode(".", $_FILES['userfile']['name']);
  20.     $nr    = count($array);
  21.     $ext  = $array[$nr-1];
  22.     if(($ext !="jpg") && ($ext !="jpeg") && ($ext !="png"))
  23.         die("<BR><BR>Dozowolone są tylko rozszerzenia jpg i png");
  24.  
  25. //CHECK TYPE: (what the browser sent)
  26. if(($_FILES['userfile']['type'] != "image/jpeg") && ($_FILES['userfile']['type'] != "image/pjpeg") && ($_FILES['userfile']['type'] != "image/png")) {
  27.    die("<BR><BR>Dozowolone są tylko rozszerzenia jpg i png");
  28. }
  29.    
  30. //DOUBLE CHECK TYPE: if image MIME type from GD getimagesize() -In case it was a FAKE!                            
  31. if(($info['mime'] != "image/jpeg") && ($info['mime'] != "image/pjpeg") && ($info['mime'] != "image/png")) {
  32.    die("<BR><BR>Dozowolone są tylko rozszerzenia jpg i png");
  33. }
  34.  
  35. //check file size (length & width)
  36. if(($info[0] > $max_width) || ($info[1] >$max_height)) {
  37.    die("<BR><BR>Obrazek jest za duży(<b>" . $info[0] . "</b> x <b>" . $info[1] . "</b>). Maksymalny rozmiar obrazka ". $max_height . " x ". $max_width .".");
  38. }
  39.  
  40. //rename file, move it to location.
  41. if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {
  42.  
  43. //get max number of images the user has uploaded
  44. $m = mysql_query("SELECT max(user_images) as `total_images` FROM `images` WHERE `user_id` = '".$_SESSION['user_id']."'");
  45.     if(!$m) die('An Error Occurred.');
  46.       $result = mysql_fetch_object($m);
  47.          if($result->total_images <= 0) {
  48.                $image_number = 1;
  49.          } else {
  50.         $image_number = $result->total_images + 1;
  51.          } //end if
  52.  
  53. $filename = strtolower($_SESSION['username']) . $image_number;
  54.  
  55.  if(move_uploaded_file($_FILES['userfile']['tmp_name'] , $_SERVER['DOCUMENT_ROOT']."/img/".$filename . '.' . $ext)) {
  56.       echo("File uploaded successfully.");  
  57.   } else {
  58.        echo("An error occurred while uploading.");
  59.   }//end upload
  60. } //end is_uploaded_file
  61.  
  62. } else { //display form ?>
  63.  
  64. <form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>" method="post" name="uploadImage" />
  65. <input type="hidden" MAX_UPLOAD_SIZE = "10000000000" />
  66. <input type="file" name="userfile" size="35" />
  67. <input type="submit" name="submit" value="Upload Image">
  68.  
  69. <? } //end else ?>

za kazdym razem pokazuje mi się informacja o zbyt duzym rozmiarze pliku, czy ktoś może mi pomoc i powiedziec gdzie jest blad?(IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
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: 9.10.2025 - 13:22