FileUpload 1.5.2 not working with vanilla 2.0.18.1

tf1tf1
edited January 2012 in Vanilla 2.0 - 2.8

The plugin is not generating thumbnails (it defines a function UtilityController_Thumbnail_Create() but it is never used). As a result, it creates links to non-existent thumb images; some browsers will supply a broken image icon, but some, notably FF, will just ignore the img tag, which makes it look as if no file has been attached to a post.

I tried to insert the UtilityController_Thumbnail_Create() function into PostController_Upload_Create() but without success.

Answers

  • I ran into this a little while back. opted to hack around it. do some searching and you should find the thread. it's a functional hack for the most part.

  • Thx. I have fixed it by simply implementing the thumbnail generation in MediaModel::ThumbnailUrl(), instead of it returning a random invalid path when the thumb does not exist.

    But at least a plugin that is not working should not be marked as Approved, it suggests no testing is being done.

  • do you mind elaborating on this? what file(s) did you touch?

  • class.mediamodel.php; added the following function:

    public static function ThumbnailCreate ($Media) {
      $SWidth = GetValue('ImageWidth', $Media);
      $SHeight = GetValue('ImageHeight', $Media);
      $Path = ltrim(GetValue('Path', $Media), '/');
    
      $Options = array();
    
      $ThumbHeight = self::ThumbnailHeight();
      $ThumbWidth = self::ThumbnailWidth();
    
      if (!$ThumbHeight || $SHeight < $ThumbHeight) {
         $Height = $SHeight;
         $Width = $SWidth;
      } else {
         $Height = $ThumbHeight;
         $Width = round($Height * $SWidth / $SHeight);
      }
    
      if ($ThumbWidth && $Width > $ThumbWidth) {
         $Width = $ThumbWidth;
    
         if (!$ThumbHeight) {
            $Height = round($Width * $SHeight / $SWidth);
         } else {
            $Options['Crop'] = TRUE;
         }
      }
    
      $TargetPath = MediaModel::PathUploads()."/thumbnails/$Path";
      if (!file_exists(dirname($TargetPath))) {
         mkdir(dirname($TargetPath), 0777, TRUE);
      }
      Gdn_UploadImage::SaveImageAs($Path, $TargetPath, $Height, $Width, $Options);
    }
    

    And then modfied relevant branch in ::ThumbUrl() (two lines marked --->) like this:

      if ($RequiresThumbnail) {
         $ThumbPath = MediaModel::PathUploads()."/thumbnails/$Path";
         if (file_exists(MediaModel::PathUploads()."/thumbnails/$Path"))
            $Result = "/uploads/thumbnails/$Path";
         else{
      --->      ThumbnailCreate ("$Path");
      --->      $Result = "/uploads/thumbnails/$Path";
    }
      } else {
         $Result = "/uploads/$Path";
      }
    
  • Above code didn't work for me:

       public static function ThumbnailCreate ($Media) {
        try{
          $SWidth = GetValue('ImageWidth', $Media);
          $SHeight = GetValue('ImageHeight', $Media);
          $Path = ltrim(GetValue('Path', $Media), '/');
          $Options = array();
          $ThumbHeight = self::ThumbnailHeight();
          $ThumbWidth = self::ThumbnailWidth();
          if (!$ThumbHeight || $SHeight < $ThumbHeight) {
             $Height = $SHeight;
             $Width = $SWidth;
          } else {
             $Height = $ThumbHeight;
             $Width = round($Height * $SWidth / $SHeight);
          }
          if ($ThumbWidth && $Width > $ThumbWidth) {
             $Width = $ThumbWidth;
             if (!$ThumbHeight) {
                $Height = round($Width * $SHeight / $SWidth);
             } else {
                $Options['Crop'] = TRUE;
             }
          }
          $TargetPath = MediaModel::PathUploads()."/thumbnails/$Path";
          if (!file_exists(dirname($TargetPath))) {
             mkdir(dirname($TargetPath), 0777, TRUE);
          }
          Gdn_UploadImage::SaveImageAs(MediaModel::PathUploads().'/'.$Path, $TargetPath, $Height, $Width, $Options);
          }catch(Exception $e) {
          }
        }
    

    And in ::ThumbUrl() (two lines marked --->) like this:

    if (file_exists(MediaModel::PathUploads()."/thumbnails/".$Path))
        $Result = "/uploads/thumbnails/".$Path;
    else
    {
        --- > self::ThumbnailCreate($Media);
        --- > $Result = "/uploads/thumbnails/$Path";
    }
    
  • This behavior appears to be browser-specific.

    With:
    Vanilla 2.0.18.4
    FileUpload 1.5.2

    Google Chrome 19.0.1084 56 m - Works flawlessly
    Firefox 11.0 - No preview displayed
    IE 8.0 - Multiple issues, including the editor toolbar being extended by multiple lines and a client-side script hanging. Upload works after killing the client-side script when prompted.

  • Pardon the formatting. I had line breaks in there...

  • Here are my test results:

    Vanilla 2.0.18.4 FileUpload 1.5.2 MacOSX 10.7.4

    Safari - Uploads file, but stalls with progressbar at 100% - no image in post
    FireFox 13.0.1 - Works for JPEG but no preview for PNG files.
    Chrome 20.0.1132.47 - JPEG Works but broken image preview for PNG files.

Sign In or Register to comment.