Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Błąd przy wgrywaniu foto
Forum PHP.pl > Forum > Przedszkole
styljola
Proszę o pomoc.
Wyskakuje mi błąd przy wgrywaniu foto do sklepu opensolution

Fatal error: Call to undefined function imagecreatefromjpeg() in /.../sklep/libraries/FotoJobs.php on line 299

Czy to świadczy o złym zadeklarowaniu funkcji?

Poniżej fragment pliku wskazany w komunikacie

  1. <?php
  2. if ( !$aImgProperties[2] == 2 ) {
  3. return null;
  4. }
  5. else {
  6. switch( $sImgExt ) {
  7. case 'jpg':
  8. $mImgCreate = ImageCreateFromJPEG( $sImgBackup );
  9. break;
  10. case 'jpeg':
  11. $mImgCreate = ImageCreateFromJPEG( $sImgBackup );
  12. break;
  13. case 'png':
  14. $mImgCreate = ImageCreateFromPNG( $sImgBackup );
  15. break;
  16. case 'gif':
  17. $mImgCreate = ImageCreateFromGIF( $sImgBackup );
  18. }
  19. ?>
Pitter
to znaczy że nie istnieje taka funkcja.
styljola
Za długi jest plik cały żeby go wkleić a nie mam pojęcia co teraz mogę z tym zrobić sad.gif
Pitter
Sprawdź czy dobrze przepisałeś nazwę funkcji. Bo ten błąd oznacza że zdefiniowana funkcja nigdzie nie jest... opisana. Czyli jest próba wywołania funkcji która nie istnieje
styljola
Komunikat skopiowałam z monitora i znalazłam ten ciąg znaków we wskazanym pliku
ani w nagłówku ani dkalej w pliku nie widzę zadeklarowanej funkcji

Fatal error: Call to undefined function imagecreatefromjpeg() in /home/styljola/public_html/sklep/libraries/FotoJobs.php on line 299

1 część pliku

  1. <?php
  2. /**
  3. * FotoJobs - changing photos
  4. * @access  public 
  5. * @version 0.1.0 
  6. * @require FileJobs
  7. * @require Trash
  8. * @date  2007-02-13 08:51:46
  9. */
  10. class FotoJobs extends FileJobs
  11. {
  12.  
  13. var $iThumbX = 100;
  14. var $iThumbY = 100;
  15. var $iQuality  = 80;
  16. var $iThumbAdd = '_m';
  17. var $iCustomThumbX = 250;
  18. var $iCustomThumbY = 250;
  19. var $sCustomThumbAdd = null;
  20. var $sExt  = 'jpg';
  21. var $sExtDot = '.jpg';
  22. var $iMaxForThumbSize = 2000;
  23. var $fRatio  = 0.80;
  24.  
  25. function &getInstance( ){
  26. static $oInstance = null;
  27. if( !isset( $oInstance ) ){
  28. $oInstance = new FotoJobs( );
  29. }
  30. return $oInstance;
  31. } // end function getInstance
  32.  
  33. /**
  34.   * Constuctor
  35.   * @return void
  36.   * @param int  $iThumbSize
  37.   */
  38. function FotoJobs( $iThumbSize = 100 ){
  39. $this->iThumbX = $iThumbSize;
  40. } // end function FotoJobs
  41.  
  42. /**
  43.   * Sets thumb size
  44.   * @return void
  45.   * @param int  $iThumbSize
  46.   */
  47. function setThumbSize( $iThumbSize = 100 ){
  48. $this->iThumbX = $iThumbSize;
  49. } // end function setThumbSize
  50.  
  51. /**
  52.   * Sets thumb quality
  53.   * @return void
  54.   * @param int  $iThumbQuality
  55.   */
  56. function setThumbQuality( $iThumbQuality = 80 ){
  57. $this->iQuality = $iThumbQuality;
  58. } // end function setThumbQuality
  59.  
  60. /**
  61.   * Sets name addition for thumb
  62.   * @return void
  63.   * @param int  $iThumbAdd
  64.   */
  65. function setThumbAdd( $iThumbAdd = '_m' ){
  66. $this->iThumbAdd = $iThumbAdd;
  67. } // end function setThumbAdd
  68.  
  69. /**
  70.   * Sets name addition for custom thumb
  71.   * @return void
  72.   * @param int  $iThumbAdd
  73.   */
  74. function setCustomThumbAdd( $sThumbAdd = null ){
  75. $this->sCustomThumbAdd = $sThumbAdd;
  76. } // end function setCustomThumbAdd
  77.  
  78. /**
  79.   * Sets max dimension of picture (when bigger thumb wont be create)
  80.   * @return void
  81.   * @param int  $iMaxForThumbSize
  82.   */
  83. function setMaxForThumbSize( $iMaxForThumbSize = 2000 ){
  84. $this->iMaxForThumbSize = $iMaxForThumbSize;
  85. } // end function setMaxForThumbSize
  86.  
  87. /**
  88.   * Sets ratio of image
  89.   * @return void
  90.   * @param int  $fRatio
  91.   */
  92. function setRatio( $fRatio = 0.80 ){
  93. $this->fRatio = $fRatio;
  94. } // end function setRatio
  95.  
  96. /**
  97.   * Upload and copy of files and create thumbs from them
  98.   * @return array
  99.   * @param string $sDestDir - destination directory
  100.   * @param mixed $mImgSrc - when upload = $_FILES or when copy = file path
  101.   * @param string $sImgOutput - suggested output file name
  102.   * @param mixed $sOption - upload or copy
  103.   */
  104. function copyAndCreateThumb( $sDestDir, $mImgSrc, $sImgOutput, $sOption = null ){
  105.  
  106. // remember thumb size
  107. $iOldSize = $this->iThumbX;
  108.  
  109. if( !is_dir( $sDestDir ) )
  110. return null;
  111.  
  112. $sImgOutput = $this->throwNameOfFile( $sImgOutput );
  113.  
  114. $sImgOutput = $this->changeFileName( $sImgOutput );
  115.  
  116. if( $sOption == 'upload' ){
  117. if( is_uploaded_file( $mImgSrc['tmp_name'] ) && is_file( $mImgSrc['tmp_name'] ) && filesize( $mImgSrc['tmp_name'] ) > 0 && $this->checkCorrectFile( $mImgSrc['name'], 'jpg|jpeg|gif|png' ) == 1 ){
  118. $this->sExt = $this->throwExtOfFile( $mImgSrc['name'] );
  119. $this->sExtDot = isset( $this->sExt ) ? '.'.$this->sExt : null;
  120. $aNewFiles['bFile'] = $this->uploadFile( $mImgSrc, $sDestDir, $sImgOutput.$this->sExtDot );
  121. }
  122. else
  123. return null;
  124. }
  125. elseif( $sOption == 'copy' ){
  126. if( is_file( $mImgSrc ) && filesize( $mImgSrc ) > 0 && $this->checkCorrectFile( $mImgSrc, 'jpg|jpeg|gif|png' ) == 1 ){
  127. $this->sExt = $this->throwExtOfFile( $mImgSrc );
  128. $this->sExtDot = isset( $this->sExt ) ? '.'.$this->sExt : null;
  129. $aNewFiles['bFile'] = $this->checkIsFile( $sImgOutput.$this->sExtDot, $sDestDir );
  130. if( !copy( $mImgSrc, $sDestDir.$aNewFiles['bFile'] ) )
  131. return null;
  132. }
  133. else
  134. return null;
  135. }
  136. $sImgPatch = $sDestDir.$aNewFiles['bFile'];
  137.  
  138. $aNewFiles['bName'] = $this->throwNameOfFile( $aNewFiles['bFile'] );
  139. $aNewFiles['sFile'] = $aNewFiles['bName'] . $this->iThumbAdd . '.' . $this->sExtDot;
  140. $aImgSize = $this->throwImgSize( $sImgPatch );
  141.  
  142. if( defined( 'MAX_DIMENSION_OF_IMAGE' ) && ( $aImgSize['width'] > MAX_DIMENSION_OF_IMAGE || $aImgSize ['height'] > MAX_DIMENSION_OF_IMAGE ) ){
  143. if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize ){
  144. $iOldAdd = $this->iThumbAdd;
  145. $this->setThumbSize( MAX_DIMENSION_OF_IMAGE );
  146. $this->setThumbAdd( '' );
  147. $aNewFiles['bFile'] = $this->createThumb( $sImgPatch, $sDestDir, $aNewFiles['bFile'] );
  148. $this->setThumbSize( $iOldSize );
  149. $this->setThumbAdd( $iOldAdd );
  150. }
  151. else
  152. return null;
  153. }
  154. ?>


2 część pliku

  1. <?php
  2. else
  3. copy( $sImgPatch, $sDestDir.$aNewFiles['sFile'] );
  4.  
  5. $aNewFiles['bWidth'] = $aImgSize['width'];
  6. $aNewFiles['bHeight']  = $aImgSize['height'];
  7. $aNewFiles['sWidth'] = $this->iThumbX;
  8. $aNewFiles['sHeight']  = $this->iThumbY;
  9. $aNewFiles['sName']  = basename( $aNewFiles['sFile'], '.'.$this->sExt );
  10. $aNewFiles['ext']  = $this->sExt;
  11.  
  12. $this->iThumbY = 100;
  13. $this->setThumbSize( $iOldSize );
  14.  
  15. return $aNewFiles;
  16. } // end function copyAndCreateThumb
  17.  
  18. /**
  19.   * Clears propeties of object (set to default)
  20.   * @return void
  21.   */
  22. function clearAll( ){
  23. $this->iThumbX = 100;
  24. $this->iThumbY = 100;
  25. } // end function clearAll
  26.  
  27. /**
  28.   * Returns image size in px
  29.   * @return array/int
  30.   * @param string $imgSrc
  31.   * @param mixed $sOption
  32.   */
  33. function throwImgSize( $imgSrc, $sOption = null ){
  34. $aImg = getImageSize( $imgSrc );
  35.  
  36. $aImgSize['width'] = $aImg[0];
  37. $aImgSize['height'] = $aImg[1];
  38.  
  39. if( $sOption == 'width' || $sOption == 'height' )
  40. return $aImgSize[$sOption];
  41. else
  42. return $aImgSize;
  43. } // end function throwImgSize
  44.  
  45. /**
  46.   * Returns image width in px
  47.   * @return int
  48.   * @param string $imgSrc
  49.   */
  50. function throwImgWidth( $imgSrc ){
  51. return $this->throwImgSize( $imgSrc, 'width' );
  52. } // end function throwImgWidth
  53.  
  54. /**
  55.   * Returns image height in px
  56.   * @return int
  57.   * @param string $imgSrc
  58.   */
  59. function throwImgHeight( $imgSrc ){
  60. return $this->throwImgSize( $imgSrc, 'height' );
  61. } // end function throwImgHeight
  62.  
  63.  
  64. /**
  65.   * Creates new custom size thumb
  66.   * @return string
  67.   * @param string $sImgSource
  68.   * @param string $sImgDestDir
  69.   * @param int $iSize
  70.   * @param string $sImgOutput
  71.   * @param bool $bOverwrite
  72.   */
  73. function createCustomThumb( $sImgSource, $sImgDestDir, $iSize = null, $sImgOutput = false, $bOverwrite = null ){
  74.  
  75. if( !is_dir( $sImgDestDir ) || $this->checkCorrectFile( $sImgSource, 'jpg|jpeg|gif|png' ) == 0 )
  76. return null;
  77.  
  78. $aImgSize = $this->throwImgSize( $sImgSource );
  79. if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize ){
  80.  
  81. $sImgExt = $this->throwExtOfFile( $sImgSource );
  82.  
  83. if( $sImgOutput == false )
  84. $sImgOutput = $this->throwNameOfFile( $sImgSource ) . $this->sCustomThumbAdd . '.' . $sImgExt;
  85.  
  86. if( !isset( $bOverwrite ) )
  87. $sImgOutput = $this->checkIsFile( $sImgOutput, $sImgDestDir );
  88.  
  89. $iOldSize = $this->iThumbX;
  90. if( is_numeric( $iSize ) )
  91. $this->setThumbSize( $iSize );
  92. else
  93. $this->setThumbSize( $this->iCustomThumbX );
  94.  
  95. $sFile = $this->createThumb( $sImgSource, $sImgDestDir, $sImgOutput );
  96. $this->setThumbSize( $iOldSize );
  97. return $sFile;
  98. }
  99. else
  100. return null;
  101. } // end function createCustomThumb
  102.  
  103.  
  104. /**
  105.   * Function make photo thumbs
  106.   * @return int
  107.   * @param string $sImgSource  - source file, from it thumb is created
  108.   * @param string $sImgDestDir - destination directory for thumb
  109.   * @param string $sImgOutput  - picture name after change (default old name with _m addition)
  110.   * @param mixed $sOption - b/d
  111.   */ 
  112. function createThumb( $sImgSource, $sImgDestDir, $sImgOutput = false, $iQuality = null, $sOption = null ) { 
  113.  
  114. if( !is_dir( $sImgDestDir ) || $this->checkCorrectFile( $sImgSource, 'jpg|jpeg|gif|png' ) == 0 )
  115. return null;
  116.  
  117. if( !is_numeric( $iQuality ) )
  118. $iQuality = $this->iQuality;
  119.  
  120. $sImgExt = $this->throwExtOfFile( $sImgSource );
  121.  
  122. if( $sImgOutput == false )
  123. $sImgOutput = basename( $sImgSource, '.'.$sImgExt ) . $this->iThumbAdd . '.' . $sImgExt;
  124.  
  125. $sImgOutput = $this->changeFileName( $sImgOutput );
  126.  
  127. $sImgBackup = $sImgDestDir.$sImgOutput . "_backup.jpg";
  128. copy( $sImgSource, $sImgBackup );
  129. $aImgProperties = GetImageSize( $sImgBackup );
  130.  
  131. if ( !$aImgProperties[2] == 2 ) {
  132. return null;
  133. }
  134. else {
  135. switch( $sImgExt ) {
  136. case 'jpg':
  137. $mImgCreate = ImageCreateFromJPG( $sImgBackup );
  138. break;
  139. case 'jpeg':
  140. $mImgCreate = ImageCreateFromJPEG( $sImgBackup );
  141. break;
  142. case 'png':
  143. $mImgCreate = ImageCreateFromPNG( $sImgBackup );
  144. break;
  145. case 'gif':
  146. $mImgCreate = ImageCreateFromGIF( $sImgBackup );
  147. }
  148.  
  149. $iImgCreateX = ImageSX( $mImgCreate );
  150. $iImgCreateY = ImageSY( $mImgCreate );
  151.  
  152. $iScaleX = $this->iThumbX / ( $iImgCreateX );
  153. $this->iThumbY = $iImgCreateY * $iScaleX;
  154.  
  155. $iRatio = $this->iThumbX / $this->iThumbY;
  156.  
  157. if( $iRatio < $this->fRatio ) {
  158. $this->iThumbY = $this->iThumbX;
  159. $iScaleY = $this->iThumbY / ( $iImgCreateY );
  160. $this->iThumbX = $iImgCreateX * $iScaleY;
  161. }
  162.  
  163. $this->iThumbX = ( int )( $this->iThumbX );
  164. $this->iThumbY = ( int )( $this->iThumbY );
  165. $mImgDest  = imagecreatetruecolor( $this->iThumbX, $this->iThumbY );
  166. unlink( $sImgBackup );
  167.  
  168. if( function_exists( 'imagecopyresampled' ) )
  169. $sCreateFunction = 'imagecopyresampled';
  170. else
  171. $sCreateFunction = 'imagecopyresized';
  172.  
  173. if( !$sCreateFunction( $mImgDest, $mImgCreate, 0, 0, 0, 0, $this->iThumbX + 1, $this->iThumbY + 1, $iImgCreateX, $iImgCreateY ) ) {
  174. imagedestroy( $mImgCreate );
  175. imagedestroy( $mImgDest );
  176. return null;
  177. }
  178. else {
  179. imagedestroy( $mImgCreate );
  180. if( !is_file( $sImgDestDir.$sImgOutput ) ) {
  181. touch( $sImgDestDir.$sImgOutput );
  182. chmod( $sImgDestDir.$sImgOutput, 0666 );
  183. }
  184. switch( $sImgExt ) {
  185. case 'jpg':
  186. $Image = ImageJPG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
  187. break;
  188. case 'jpeg':
  189. $Image = ImageJPEG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
  190. break;
  191. case 'png':
  192. $Image = ImagePNG( $mImgDest, $sImgDestDir.$sImgOutput );
  193. break;
  194. case 'gif':
  195. if( function_exists( "imagegif" ) )
  196. $Image = ImageGIF( $mImgDest, $sImgDestDir.$sImgOutput );
  197. else{
  198. if( $iQuality > 0 )
  199. $iQuality = floor( ( $iQuality - 1 ) / 10 );
  200. $Image = ImagePNG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
  201. }
  202. }
  203. if ( $Image ) {
  204. imagedestroy( $mImgDest );
  205. return $sImgOutput;
  206. }
  207. imagedestroy( $mImgDest );
  208. }
  209. return null;
  210. }
  211.  
  212. } // end function createThumb
  213.  
  214. };
  215. ?>
tomm
Być może masz starszą wersję biblioteki GD
tutaj masz info http://pl2.php.net/manual/pl/function.imag...atefromjpeg.php
spróbuj zakomentować ten przypadek case i zobacz co wtedy
styljola
Przeszło ale zatrzymało się na lini 308

Fatal error: Call to undefined function imagesx() in /home/styljola/public_html/sklep/libraries/FotoJobs.php on line 308

Kod
      /* case 'jpeg':
          $mImgCreate = ImageCreateFromJPEG( $sImgBackup );
            break;*/
        case 'png':
          $mImgCreate = ImageCreateFromPNG( $sImgBackup );
            break;
        case 'gif':
          $mImgCreate = ImageCreateFromGIF( $sImgBackup );
      }

      $iImgCreateX = ImageSX( $mImgCreate );


Czy tez zakomentować ?
nospor
Cytat
spróbuj zakomentować ten przypadek case i zobacz co wtedy
ale rada winksmiley.jpg

@styljola czy ty wogole masz zainstalowaną biblioteke GD?
http://pl.php.net/manual/pl/image.installation.php
styljola
Własnie wysłałam pytanko do właściciela serwera blinksmiley.gif shou.pl
tomm
szczerze powiedziawszy obie funkcje są ze standardowej biblioteki GD
jeśli pracujesz na localhoscie wyedytuj plik php.ini i odkomentuj linię
extension=php_gd2.dll
zrestartuj serwer i spróbuj ponownie uruchomić skrypt

@nospor
@styljola czy ty wogole masz zainstalowaną biblioteke GD?

gdyby nie miał to wywalałoby błąd przy każdej funkcji typu imagecreate....
nospor
Cytat
@nospor
@styljola czy ty wogole masz zainstalowaną biblioteke GD?

gdyby nie miał to wywalałoby błąd przy każdej funkcji typu imagecreate....
tak, tylko ze imagecreatefromjpeg jest wywolywane najpierw i od razu sie na niej pluje fatal errorem wiec nigdzie dalej nie dochodzi.... winksmiley.jpg

a tak na marginesie to
nie: ImageCreateFromJPEG
a: imagecreatefromjpeg

czasami moze chodzic o wielkosc liter
-tomm-
dlatego właśnie zaproponowałem aby zakomentować tego case i zobaczyć czy na następnym jakimś image..... też się wysypie, jak widać przeszło zarówno przez imagecreatefrompng, jaki przez im.............gif co świdczy o zainstalowanej GD. Moim skromnym zdaniem może to być spowodowane starszą wersją GD, ale poczekajmy na odpowiedź właściciela serwera.
nospor
Cytat
jak widać przeszło zarówno przez imagecreatefrompng, jaki przez im.............gif co świdczy o zainstalowanej GD
Ale czy ty wiesz jak dziala SWITCH? Widze ze nie wiesz, wiec zajrzyj do manuala i nie gadaj takich rzeczy bo jeszcze jakis poczatkujący uzna ze mądrze prawisz...
Przeciez jak wykomentowales jednego case do ktorego skrypt wchodzil to go wykomentowales. Skrypt nie wejdzie do innych case bo one nie spelniaja warunku. Warunek spelnial tylko case ktory wlasnie wykomentowales... a skoro skrypt nie wejdzie do innych case to nie bedzie go obchodzilo ze jest w nich jakas funkcja, ktora nie jest zdefiniowana.
Po wykomentowaniu jedynego slusznego case, skrypt wywalil sie na pierwszej funkcji z rodziny GD jaką napotkal, czyli ImageSX

edit down:
Cytat
ale po co kubusiu zaraz te nerwy?
Bo sie nie znasz (lub jak wolisz: "przeaczasz drobny mankament" ) i klocisz a tlumacze ci to od kilku postow a ty ciagle swoje winksmiley.jpg
-tomm-
rzeczywiście przoczyłem ten "drobny" mankament smile.gif
ale po co kubusiu zaraz te nerwy?
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.