Using [inline_upload|file=1] when I've uploaded a single image file does not work. I get "not found: 1"

I stepped through with eclipse debugger and found where it's tripping up. inline_upload.module line 70:

      if (is_int($params['file']) && isset($params['#node'])) {
70      if (isset($params['#node']->files[$params['file']])) {
          $params['file'] = $params['#node']->files[$params['file']]->filename;
        }
      }

Looking at the variables I have $params['#node']->files[12] set, but not $params['#node']->files[1]

Looking at the database, 12 is the fid for the uploaded file. Using [inline_upload|file=12] shows the image correctly. It seems that the index it is looking for is off.

Comments

Bryan76’s picture

Confirmed. It appears that node_load builds the node in such a way that the files array $params['#node']->files does not use a sequential index. Instead it uses the uniqe fid from the drupal_files table as an index.

I have an idea or two on how to handle this.

Bryan76’s picture

I have made a patch that "corrects" this issue. It may not be coded to drupal standards, so use at your own risk, but maybe it can be a starting point.

One thing I did is add an additional parameter "attachid". I didn't like the idea of using the file parameter to mean either a filename or a numerical attachment offset. In my mind it should only be one thing. So I made it an optional parameter and added an additional one.

[inline_upload|file=filename.jpg|title=Some Text]

-or-

[inline_upload|attachid=1|title=Some Text] (uses the first attachment. Attachment numbering starts at 1)

sun’s picture

Status: Active » Fixed
StatusFileSize
new1.02 KB

Thanks for reporting, reviewing, and testing! Committed attached patch to 2.x.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.