Skip to content

Fix incorrect URL generation in getContentUrl() - #3759

Merged
nao-pon merged 1 commit into
Studio-42:masterfrom
darth-antony:fix/getContentUrl-path-bug
Apr 17, 2026
Merged

Fix incorrect URL generation in getContentUrl()#3759
nao-pon merged 1 commit into
Studio-42:masterfrom
darth-antony:fix/getContentUrl-path-bug

Conversation

@darth-antony

Copy link
Copy Markdown
Contributor

trim($this->root, '/') strips the leading slash from the root path, making strlen() return a value 1 less than expected. This causes substr() to include an extra character from the root folder name in the relative path.

For example, with root folder "images":

  • Expected URL: /files/image.jpg
  • Actual URL: /files/s/image.jpg

Using strlen($this->root) + 1 is consistent with other URL construction methods in elFinderVolumeLocalFileSystem (lines 206, 612, 845, 1420) which all use this correct pattern.

Fixes #3746

trim($this->root, '/') strips the leading slash from the root path,
making strlen() return a value 1 less than expected. This causes
substr() to include an extra character from the root folder name
in the relative path.

For example, with root folder "images":
- Expected URL: /files/image.jpg
- Actual URL:   /files/s/image.jpg

Using strlen($this->root) + 1 is consistent with other URL
construction methods in elFinderVolumeLocalFileSystem (lines 206,
612, 845, 1420) which all use this correct pattern.

Fixes Studio-42#3746
@Smanst3r

Copy link
Copy Markdown

Any news on this https://github.com/Studio-42/elFinder/blob/master/php/elFinderVolumeDriver.class.php#L3334?
I have the same issue but I thought it could be done with rtrim($this->root..)... instead of trim($this->root...
and return rtrim($this->URL, '/') . $path;
Kind regards

@nao-pon

nao-pon commented Apr 17, 2026

Copy link
Copy Markdown
Member

@darth-antony That makes sense.

I think this became visible mainly in the immediate post-upload flow, where the backend has not yet exposed a stable stat URL and getContentUrl() is used directly. After reload, the normal stat data path hides the issue.

So the root cause explanation in the PR may be a bit simplified, but the fix direction itself still looks valid.

@nao-pon
nao-pon merged commit 2ce950f into Studio-42:master Apr 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

elfinder cannot open the file that has just been uploaded

3 participants