Following on from some PHP 5 problems, I think there's a path issue when using private files. I am using private files with the files directory set one directory above the 'Drupal root', ie ../files.

It seems the $filepath used in this call on line 262:

    $image = theme('image',
      $file->filepath,
      $title,
      $title,
      array('class' => 'inline')
    );

is incorrect for me: it contains ../files/greg_pattillo.jpg instead of /system/files/greg_pattillo.jpg. I tried passing the variable through file_create_url() to no avail - in this case the fully qualified URL - http://paul.leafish.co.uk/system/files/greg_pattillo.jpg is passed to the theme function and it returns nothing.

CommentFileSizeAuthor
#4 inline.module.private.patch1.06 KBsun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

I've never tried to use Inline with private files...
Since file_create_url() returns a full URI and we only need a path, it seems we have to deal with private files on our own.

leop’s picture

I changed line 275:

$html = l($image, $file->filepath, $attributes, NULL, NULL, FALSE, TRUE);

to

$html = l($image, file_create_url($file->filepath), $attributes, NULL, NULL, FALSE, TRUE);

which did the job, but then, my "files" directory still is below the drupal root. I will move the "files" directory and try it again.

leop’s picture

I checked it for both private files within and outside the web directory, and for public files, and in all cases changing line 275 -- as stated in my previous post -- works. (nothing was changed in line 262 and below)

sun’s picture

FileSize
1.06 KB

@leo_pape: The line you changed only affects the link to the inlined file or image, not the file itself.

As far as I can see, the key for private file support is the function function inline_prepare_file_object(). The file path is already adjusted for node previews there. You might want to apply the current documentation patch to gain more information about what happens where.

By speaking of this, you might try the attached patch.

sun’s picture

Status: Active » Needs review
pips1’s picture

Status: Needs review » Needs work

I also would love to be able to get inline images with 'private files' enabled.

@leo_pape: I tested changing that line of code you suggested. The result is that [inline:01] will now place a working link to the attached image (before the code change the link to the image wouldn't work at all), but the image isn't displayed inline. :-(

@sun: I tested applying your patch. Unfortunately, the result doesn't work for me. I get the error message: "warning: getimagesize(system/files//home/username/private/www.example.tld/image_640.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/username/drupal-sites/www.example.tld/modules/inline/inline.module on line 438."

Please note (I don't know if this is really relevant): I haven't installed 'imagecache', because the scaling-on-the-fly functionality isn't critical for me and imagecache doesn't currently support 'private files' anyway... just mentioning this for the sake of completeness.

wvengen’s picture

I'm replacing part of theme_inline_img on line 62:

    $image = theme('image',
      $file->filepath,
      $title,
      $title,
      array('class' => 'inline')
    );

by the following to get it working without imagecache:

    list($width, $height, $type, $image_attributes) = @getimagesize($path);
    $image = '<img src="'. file_create_url($file->filepath) .'" alt="" '. $image_attributes . ' class="inline" />';
wvengen’s picture

oops, that must be @getimagesize($file->filepath) instead

sun’s picture

Status: Needs work » Closed (duplicate)

Marking as duplicate of #192586: Private files support