Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

Categories

In this Discussion

Who's Online 11

CurtisOdenUnderDogericgilletteestevdtc74422 +4 guests

FileUpload 1.5.2 not working with vanilla 2.0.18.1

This discussion is related to the FileUpload addon.

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.

Comments

  • hbfhbf
    Posts: 654

    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.

  • tf1tf1
    Posts: 3 1 like

    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.

  • hbfhbf
    Posts: 654

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

  • tf1tf1
    Posts: 3

    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";
      }
    
  • Posts: 1

    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";
    }
    
Sign In or Register to comment.