2012-02-19 96 views
1

我在phpthumb中遇到了一个非常有问题的错误:http://phpthumb.gxdlabs.com/ 所以基本上,我有一个上传配置文件图片的表单。上传似乎工作,因为它上传目录中的图像。问题是它不会生成缩略图,但我确定所有变量和名称都是正确的。它给了我以下错误。特别是“未找到图像文件”:如何使用phpthumb上传缩略图?

Fatal error: Uncaught exception 'Exception' with message 'Image file not found: ����' in {PATH}\phpthumb\ThumbBase.inc.php:193 Stack trace: #0 {PATH}\phpthumb\ThumbBase.inc.php(172): ThumbBase->triggerError('Image file not ...') #1 {PATH}\phpthumb\ThumbBase.inc.php(110): ThumbBase->fileExistsAndReadable() #2 {PATH}\phpthumb\GdThumb.inc.php(96): ThumbBase->__construct('??????JFIF?????...', false) #3 G:\EasyPHP\www\YourSlab\phpthumb\ThumbLib.inc.php(127): GdThumb->__construct('??????JFIF?????...', Array, false) #4 {PATH}\edit_profile.php(74): PhpThumbFactory::create('??????JFIF?????...') #5 {PATH}\edit_profile.php(80): generateThumbnail->createthumbnail(25) #6 {PATH}\edit_profile.php(118): set_profile_info('Mico Abrina', '1', 'asdf', 'asdf', '', 'asdf', 'asdf', '', '05', '4', '1996', 'G:\EasyPHP\tmp\...') #7 {main} thrown in {PATH}\phpthumb\ThumbBase.inc.php on line 193 

我认为它是因为我在上传后立即生成缩略图。我如何使它工作?

<?php 
    //upload images 
    if (file_exists($profile_pic)) { 
     $src_size = getimagesize($profile_pic); 

     if ($src_size['mime'] === 'image/jpeg'){ 
      $src_img = imagecreatefromjpeg($profile_pic); 
     } else if ($src_size['mime'] === 'image/png') { 
      $src_img = imagecreatefrompng($profile_pic); 
     } else if ($src_size['mime'] === 'image/gif') { 
      $src_img = imagecreatefromgif($profile_pic);  
     } else { 
      $src_img = false; 
     } 

     if ($src_img !== false) { 
      $md5sessionid = md5($_SESSION['user_id'].'asdf'); 
      imagejpeg($src_img, "profile_pic/$md5sessionid.jpg"); 
      //end of uploading images 

      //image thumbnail creation class 
      class generateThumbnail { 
       public function createthumbnail($size) { 
       $md5sessionidsecret = md5($_SESSION['user_id'].'asdf'); 
       $md5sessionidthumb = md5($md5sessionidsecret.''.$size); 
       $path_to_thumb_pic = 'profile_pic/'.$md5sessionidthumb.'.jpg'; 
       $profile_pic = file_get_contents('profile_pic/'.$md5sessionidsecret.'.jpg'); 
       $thumb_profile_pic = PhpThumbFactory::create($profile_pic); 
       $thumb_profile_pic->adaptiveResize($size, $size); 
       $thumb_profile_pic->save($path_to_thumb_pic); 
       } 
      } 
      //make the thumbnails 
      $createThumbnail = new generateThumbnail(); 
      $createThumbnail->createthumbnail(25); 
      $createThumbnail->createthumbnail(75); 
      $createThumbnail->createthumbnail(175); 
     } 
    } 
?> 

回答

1

看来,PhpThumbFactory::create()需要一个文件路径作为第一个参数,除非你第三isDataStream参数指定true。这就是为什么你在异常中得到奇怪的输出,它说Image File Not Found

你可以做一些事情来解决它:

// Either skip the file_get_contents call and pass the file path directly 
$thumb_profile_pic = PhpThumbFactory::create('profile_pic/'.$md5sessionidsecret.'.jpg'); 

// or set the 3rd parameter isDataStream to true 
$profile_pic = file_get_contents('profile_pic/'.$md5sessionidsecret.'.jpg'); 
$thumb_profile_pic = PhpThumbFactory::create($profile_pic, array(), true); 
+0

感谢那些工作非常出色! – 2012-02-19 08:46:35

+1

看来你不能传递变量。这个命令使它工作。 $ thumb_profile_pic = PhpThumbFactory :: create('profile_pic /'.$ md5sessionidsecret。'。jpg'); – 2012-02-19 08:47:12

+0

是的,我也不确定。我查看了代码,看起来他们想要实现数据流,正如它在几处提到的一样,但是查看代码我并不认为它实际上可行,但我不知道我是否正在查看旧版本。很高兴它的工作。 – drew010 2012-02-19 08:50:22

相关问题