Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Domowy upload
Forum PHP.pl > Forum > Przedszkole
pawel21a
Cześć.

Chciałem sobie zrobić taki prywatny kącik na serwerze www ze zdjęciami. Znalazłem darmowy skrypt jednak podczas uploadu wyskakuje taki błąd

Parse error: syntax error, unexpected $end in /home/u989632380/public_html/lib/bmp.class.php on line 1

  1. <?php if(!defined('cfih') or !cfih) die('This file cannot be directly accessed.');
  2.  
  3.  
  4. /***
  5.  * Fonction: ImageCreateFromBMP
  6.  * Author: DHKold
  7.  * Contact: admin@dhkold.com
  8.  * Date: The 15th of June 2005
  9.  * Version: 2.0B
  10.  */
  11. if( ! function_exists('ImageCreateFromBMP') ){
  12. function ImageCreateFromBMP($filename){
  13. //Ouverture du fichier en mode binaire
  14. if (! $f1 = fopen($filename,"rb")) return FALSE;
  15.  
  16. //1 : Chargement des ent?tes FICHIER
  17. $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14));
  18. if ($FILE['file_type'] != 19778) return FALSE;
  19.  
  20. //2 : Chargement des ent?tes BMP
  21. $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
  22. '/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
  23. '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40));
  24. $BMP['colors'] = pow(2,$BMP['bits_per_pixel']);
  25. if ($BMP['size_bitmap'] == 0) $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
  26. $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
  27. $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
  28. $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);
  29. $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4);
  30. $BMP['decal'] = 4-(4*$BMP['decal']);
  31. if ($BMP['decal'] == 4) $BMP['decal'] = 0;
  32.  
  33. //3 : Chargement des couleurs de la palette
  34. $PALETTE = array();
  35. if ($BMP['colors'] < 16777216){
  36. $PALETTE = unpack('V'.$BMP['colors'], fread($f1,$BMP['colors']*4));
  37. }
  38.  
  39. //4 : Cr?ation de l'image
  40. $IMG = fread($f1,$BMP['size_bitmap']);
  41. $VIDE = chr(0);
  42.  
  43. $res = imagecreatetruecolor($BMP['width'],$BMP['height']);
  44. $P = 0;
  45. $Y = $BMP['height']-1;
  46. while ($Y >= 0) {
  47. $X=0;
  48. while ($X < $BMP['width']){
  49. if ($BMP['bits_per_pixel'] == 24)
  50. $COLOR = unpack("V",substr($IMG,$P,3).$VIDE);
  51. elseif ($BMP['bits_per_pixel'] == 16){
  52. $COLOR = unpack("n",substr($IMG,$P,2));
  53. $COLOR[1] = $PALETTE[$COLOR[1]+1];
  54. }elseif ($BMP['bits_per_pixel'] == 8){
  55. $COLOR = unpack("n",$VIDE.substr($IMG,$P,1));
  56. $COLOR[1] = $PALETTE[$COLOR[1]+1];
  57. }elseif ($BMP['bits_per_pixel'] == 4){
  58. $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
  59. if (($P*2)%2 == 0) $COLOR[1] = ($COLOR[1] >> 4) ; else $COLOR[1] = ($COLOR[1] & 0x0F);
  60. $COLOR[1] = $PALETTE[$COLOR[1]+1];
  61. }elseif ($BMP['bits_per_pixel'] == 1){
  62. $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
  63. if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7;
  64. elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
  65. elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
  66. elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
  67. elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
  68. elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
  69. elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
  70. elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
  71. $COLOR[1] = $PALETTE[$COLOR[1]+1];
  72. }else
  73. return FALSE;
  74. imagesetpixel($res,$X,$Y,$COLOR[1]);
  75. $X++;
  76. $P += $BMP['bytes_per_pixel'];
  77. }
  78. $Y--;
  79. $P+=$BMP['decal'];
  80. }
  81.  
  82. //Fermeture du fichier
  83. fclose($f1);
  84.  
  85. return $res;
  86. }
  87. }
  88.  
  89.  
  90.  
  91. /***
  92.  * Save 24bit BMP files
  93.  * Author: de77
  94.  * Licence: MIT
  95.  * Webpage: de77.com
  96.  * Article about this class: <a href="http://de77.com/php/load-and-save-bmp-in-php-imagecreatefrombmp-imagebmp" target="_blank">http://de77.com/php/load-and-save-bmp-in-p...rombmp-imagebmp</a>
  97.  * First-version: 07.02.2010
  98.  * Version: 02.07.2010
  99.  */
  100. if( ! function_exists('imagebmp') ){
  101. function imagebmp(&$img, $filename = false){
  102. $wid = imagesx($img);
  103. $hei = imagesy($img);
  104. $wid_pad = str_pad('', $wid % 4, "\0");
  105. $size = 54 + ($wid + $wid_pad) * $hei * 3; //fixed
  106. //prepare & save header
  107. $header['identifier'] = 'BM';
  108. $header['file_size'] = dword($size);
  109. $header['reserved'] = dword(0);
  110. $header['bitmap_data'] = dword(54);
  111. $header['header_size'] = dword(40);
  112. $header['width'] = dword($wid);
  113. $header['height'] = dword($hei);
  114. $header['planes'] = word(1);
  115. $header['bits_per_pixel'] = word(24);
  116. $header['compression'] = dword(0);
  117. $header['data_size'] = dword(0);
  118. $header['h_resolution'] = dword(0);
  119. $header['v_resolution'] = dword(0);
  120. $header['colors'] = dword(0);
  121. $header['important_colors'] = dword(0);
  122.  
  123. if ($filename){
  124. $f = fopen($filename, "wb");
  125. foreach ($header AS $h){
  126. fwrite($f, $h);
  127. }
  128. //save pixels
  129. for ($y=$hei-1; $y>=0; $y--){
  130. for ($x=0; $x<$wid; $x++){
  131. $rgb = imagecolorat($img, $x, $y);
  132. fwrite($f, byte3($rgb));
  133. }
  134. fwrite($f, $wid_pad);
  135. }
  136. fclose($f);
  137. }else{
  138. foreach ($header AS $h){
  139. echo $h;
  140. }
  141. //save pixels
  142. for ($y=$hei-1; $y>=0; $y--){
  143. for ($x=0; $x<$wid; $x++){
  144. $rgb = imagecolorat($img, $x, $y);
  145. echo byte3($rgb);
  146. }
  147. echo $wid_pad;
  148. }
  149. }
  150. }
  151.  
  152. function byte3($n){return chr($n & 255) . chr(($n >> 8) & 255) . chr(($n >> 16) & 255); }
  153. function dword($n){return pack("V", $n);}
  154. function word($n){return pack("v", $n);}
  155. }


Ja nie jestem nawet na poziomie przedszkola więc nie wiem co gdzie i jak :/ Czytałem że prawdopodobnie chodzi o niezamkniętą klamrę ja jednak nie potrafię jej zlokalizować :/
Bardzo proszę o pomoc smile.gif
Turson
Podmień pierwszą linijkę na:
  1. <?php if(!defined('cfih') || !cfih){ die('This file cannot be directly accessed.');}

Mimo że jest prawidłowo, ale spróbuj.


Na pewno pokazałeś nam plik bmp.class.php? Bo to nie wygląda na klasę
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.