Mam skrypt dodawania obrazków :
laduj.php
  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  2. <?php
  3. if (isset ($_POST["submit"])) {
  4.  
  5. include ("upload.php");
  6.  
  7. $image = new Image($_FILES['file']['name']);
  8. $image -> PicDir = "uploads/";
  9. $image -> TmpName = $_FILES['file']['tmp_name'];
  10. $image -> newHeight = '100';
  11. $image -> newWidth = '100';
  12. $image -> FileSize  = $_FILES['file']['size'];
  13. $image -> FileType  = $_FILES['file']['type'];
  14.  
  15. //$image -> Save(); //use this if you wish images without resizing
  16. $image -> Resize ();
  17. } else {
  18. ?><?php
  19. }
  20. ?>
  21. <form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
  22. <input type="file" name="file" size="40">
  23. <input type="submit" name="submit" value="dodaj">
  24. </form>

Sam nie pisałem tych skryptów dlatego mam z tym problem.. Więc stąd moje pytania.. po to jest
  1. <?php
  2. }
  3. ?>
w 1 pliku ?
Dlaczego obrazek nie zawsze się pojawia ?
Dlaczego znowu wyskakuje po załadowaniu zdjęcia i wyświetleniu informacji pasek ładowania obrazka na samym dole ?
Jak podnieść infomację o załadowanym obrazku do góry ?
Wiem, że sporo tego ale z góry dzięki ! biggrin.gif

I drugi skrypt..
i upload.php
  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  2. <?php
  3. class Image {
  4. var $FileName;
  5. var $FileSize;
  6. var $FileType;
  7. var $AllowedExtentions = array ("image/png", "image/gif", "image/jpeg", "image/jpg");
  8. var $newWidth; // new width
  9. var $newHeight; //new height
  10. var $TmpName;
  11. var $PicDir; //store uploaded images
  12. var $MaxFileSize = 500000; //kbytes
  13. var $ImageQuality = 75; // image compression (max value 100)
  14. function GetInfo() {
  15. $out=' <br><br>ZdjÄ™cie zostaĹ‚o dodane!<br>
  16. Name: '.$this->FileName.'<br>
  17. file size: '.$this->FileSize.' byte<br>
  18. file type: '.$this->FileType.'<br>
  19. <img src=' . dirname($_SERVER['PHP_SELF']) . '/' . $this->PicDir . $this->FileName . '><br><br>';
  20.  
  21. return $out;
  22.  
  23. }
  24. function Image($FileName)
  25. {
  26. $this->FileName=$FileName;
  27. }
  28.  
  29.  
  30.  
  31.  function GetFileExtention ($FileName) {
  32. if (in_array ($this->FileType, $this -> AllowedExtentions)) {
  33. return true;
  34. }  else {
  35.  return false;  
  36. }
  37.  
  38.  }
  39.  
  40.  function ExistFile () {
  41. $fileexist = $_SERVER['DOCUMENT_ROOT'] .
  42. dirname($_SERVER['PHP_SELF']) .
  43. '/' . $this->PicDir . 
  44. $this->FileName;
  45. if (file_exists($fileexist)) { return true; }
  46.  }
  47.  
  48. function GetError ($error) {
  49.  
  50. switch ($error) {  
  51. case 0 :
  52. echo "ZĹ‚e rozszerzenie pliku <b>$this->FileType</b>! Dopuszczalne typy: .jpg, .jpeg, .gif, .png <b>$this->FileName</b><br>";
  53. break;
  54.  
  55. case 1 :
  56. echo "ZdjÄ™cie <b>$this->FileSize</b> jest za duĹĽe.<br>";
  57. break;  
  58.  
  59. case 2 :
  60. echo "ProszÄ™ wybrać zdjÄ™cie.<br>";
  61. break;
  62.  
  63. case 3 :
  64. echo "Error: File <b>$this->FileName</b> already exist!<br>";
  65. break;  
  66. }
  67.  
  68. }
  69.  function Resize () {
  70. if (empty ($this->TmpName))  {echo $this -> GetError (2);}
  71. else if ($this->FileSize > $this->MaxFileSize) {echo $this -> GetError (1);}  
  72. else if ($this -> GetFileExtention ($this->FileName) == false)  {echo $this -> GetError (0);}
  73. else if ($this -> ExistFile())  {echo $this -> GetError (3);}
  74.  
  75. else {
  76.  
  77. $ext = explode(".",$this->FileName);
  78. $ext = end($ext);
  79. $ext = strtolower($ext);
  80.  
  81. // Get new sizes
  82. list($width_orig, $height_orig) = getimagesize($this->TmpName);
  83.  
  84. $ratio_orig = $width_orig/$height_orig;
  85.  
  86. if ($this->newWidth/$this->newHeight > $ratio_orig) {
  87.  $this->newWidth = $this->newHeight*$ratio_orig;
  88. } else {
  89.  $this->newHeight = $this->newWidth/$ratio_orig;
  90. }
  91.  
  92. $normal = imagecreatetruecolor($this->newWidth, $this->newHeight);
  93.  
  94. if ($ext == "jpg") { $source = imagecreatefromjpeg($this->TmpName); }
  95. else if  ($ext == "gif") { $source = imagecreatefromgif ($this->TmpName); }
  96. else if  ($ext == "png") { $source = imagecreatefrompng ($this->TmpName); }
  97.  
  98. imagecopyresampled($normal, $source, 0, 0, 0, 0, $this->newWidth, $this->newHeight, $width_orig, $height_orig);
  99.  
  100.  
  101. if ($ext == "jpg") {
  102. //ob_start();
  103. imagejpeg($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality");
  104. //$binaryThumbnail = ob_get_contents();
  105. //ob_end_clean();
  106. }
  107. else if  ($ext == "gif") { imagegif ($normal, '', "$this->ImageQuality"); }
  108. else if  ($ext == "png") { imagepng ($normal, '', "$this->ImageQuality"); }
  109.  
  110. imagedestroy($source);
  111.  
  112.  echo $this -> GetInfo();
  113.  
  114.  }  
  115.  
  116. }
  117. function Save() {  
  118. if (empty ($this->TmpName))  {echo $this -> GetError (2);}
  119. else if ($this->FileSize > $this->MaxFileSize) {echo $this -> GetError (1);}  
  120. else if ($this -> GetFileExtention ($this->FileName) == false)  {echo $this -> GetError (0);}
  121. else if ($this -> ExistFile ())  {echo $this -> GetError (3);}
  122.  
  123. else {
  124.  
  125. copy($this->TmpName,$this->PicDir.$this->FileName);
  126.  
  127. echo $this -> GetInfo();
  128.  
  129.  }
  130.  }
  131.  }
  132.  
  133. ?>