Bug #60415
closedImporting images from pages media field fails if filepath contains whitespaces
0%
Description
lib.slideshow = FILES stdWrap.wrap = <div class="slideshow">|</div> references { table = pages uid.data = page:uid fieldName = media } renderObj = IMAGE renderObj { file.import.data = file:current:publicUrl altText.data = file:current:title // page:title } }
Updated by Sven Tappert almost 10 years ago
The above TS setup works perfect until 6.1. Since 6.2 the publicUrl function in \Core\Resource\Driver\LocalDriver::getPublicUrl()
encodes the file name with rawurlencode().
This might be intended, but if the file name or path contains whitespaces, the image file will not be rendered, because the encoded filepath cannot be found in the filesystem:
In \TYPO3\CMS\Core\Resource\ResourceFactory::retrieveFileOrFolderObject()
the file cannot be found ($input holds the rawurlencoded filepath for the given TS setup).
// e.g. $input = 'fileadmin/user_upload/filename%20with%20whitespaces.jpg' $input = \TYPO3\CMS\Core\Utility\PathUtility::getCanonicalPath(ltrim($input, '/')); if (@is_file(PATH_site . $input)) { // only the local file return $this->getFileObjectFromCombinedIdentifier($input); }
It's not clear to me, if getCanonicalPath()
should remove the urlencoding, if the encoding should be removed inbetween or if LocalDriver::getPublicUrl() should not encode the url at all.
I also proposed to use this alternative TS setup:
file.import.data = file:current:localPath
Unfortunately this will create a temporary file with ugly filename instead of using the original file (e.g. "typo3temp/fal-tempfile-wHoMB2.jpg"), which is absolutely unacceptable with regard to ranking optimized filenames.
Updated by Markus Klein almost 10 years ago
Why are you handing in the path all? If you have the file object, you can simply use the uid. That should work easily.
file.import.data = file:current:uid file.treatIdAsReference = 1
Example taken from css_styled_content
Updated by Markus Klein almost 10 years ago
- Status changed from New to Needs Feedback
Updated by Sven Tappert almost 10 years ago
Thank you for your quick reply Markus! I stumbled about it in css_styled_content in the meantime and this solution works perfectly. However all sample snippets I've seen before were using the publicUrl code.
Updated by Markus Klein almost 10 years ago
- Status changed from Needs Feedback to Closed
Well, these samples are not official samples I hope. ;-)