[TYPO3-english] Manually insert image in sys_file table is not working properly in backend of typo3 7 version
Jigal van Hemert
jigal.van.hemert at typo3.org
Thu Apr 14 18:42:43 CEST 2016
Hi,
On 14/04/2016 15:40, Jainish Senjaliya wrote:
> How can we generate identifier_hash and folder_hash while insert media
> in sys_file table ??
>
> Without that its throwing error message in backend.. if we added
> "fileadmin/" folder in "identifier" field like : "
> fileadmin/user_upload/js_contactform/jainish.png" than its working fine.
> but this is not a solution.
Do not directly manipulate the sys_file table. To import a file in FAL
you can simply use an API function (short class names to save some space).
// Build identifier from the absolute path to the file
$identifier = PathUtility::getRelativePath(PATH_site,
PathUtility::dirname($targetFile)) .
PathUtility::basename($targetFile);
// Import it into FAL and get a file object back
/** @var \TYPO3\CMS\Core\Resource\File $fileObject */
$fileObject =
ResourceFactory::getInstance()->retrieveFileOrFolderObject($identifier);
// Get the UID of the new FAL record
$newRecordId = $fileObject->getUid();
This will simply use the default storage (0). If you need to add it to a
specific storage you can use (with the $identifier from above)
$fileObject = ResourceFactory::getInstance()
->getFileObjectByStorageAndIdentifier($storageUid, $identifier);
--
Jigal van Hemert
TYPO3 CMS Active Contributor
TYPO3 .... inspiring people to share!
Get involved: typo3.org
More information about the TYPO3-english
mailing list