简体   繁体   English

Typo3:如何上传文件并创建文件参考?

[英]Typo3: How to upload a file and create a file reference?

i'll try to upload a file (or later multiple files) in FE. 我将尝试在FE中上传文件(或更高版本的多个文件)。 This works, like my current code. 这与我当前的代码一样有效。 But how can i get a file reference of this file now? 但是我如何才能获得此文件的文件引用?

/**
 *
 * @var array $fileData
 * @var integer $feUserId
 * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference
 */
private function uploadFile($fileData, $feUserId) {
    $storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
    $storage           = $storageRepository->findByUid(1); # Fileadmin = 1
    $saveFolder        = $storage->getFolder($this->settings['uploadFolder']);

    // Datei speichern
    $fileObject = $storage->addFile($fileData['tmp_name'], $saveFolder, $feUserId.'_'.$fileData['name']);

    // Dateiobjekt
    $repositoryFileObject = $storage->getFile($fileObject->getIdentifier());

    die(\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($repositoryFileObject));
    #$newFileReference = $this->objectManager->get('TYPO3\CMS\Extbase\Domain\Model\FileReference');
    #$newFileReference->setOriginalResource($repositoryFileObject);

    return $newFileReference;
}

There should be something like »setFileReference« by now, but I can not find the like in the API http://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_resource_1_1_file_reference.html 现在应该有类似»setFileReference«的东西,但我在API中找不到类似的内容http://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_resource_1_1_file_reference.html

Well, you may wanna use the following script as temporary solution, which uses the datamap process to create file references. 好吧,您可能希望使用以下脚本作为临时解决方案,它使用数据映射过程来创建文件引用。

$sys_file_uid = $file->getUid();
$tt_content_uid = 42;
$tt_content_pid = 1337;

// Do not directly insert a record into sys_file_reference, as this bypasses all sanity checks and automatic updates done!
$data = array();
$data['sys_file_reference']['NEW' . $sys_file_uid] = array(
    'uid_local' => $sys_file_uid,
    'table_local' => 'sys_file',
    'uid_foreign' => $tt_content_uid,
    'tablenames' => 'tt_content',
    'fieldname' => 'image',
    'pid' => $tt_content_pid,
);
$data['tt_content'][$tt_content_uid] = array('image' => 'NEW' . $sys_file_uid);

$tce = t3lib_div::makeInstance('t3lib_TCEmain'); // create TCE instance
$tce->start($data, array());
$tce->process_datamap();
if ($tce->errorLog) {
    // Error - Reference not created
    // t3lib_utility_Debug::viewArray($tce->errorLog);
}
else {
    // Success - Reference created
}

after hitting google for a while i figured out a article that sounded quite well to me.. gonna examine it tomorrow: http://insight.helhum.io/post/85015526410/file-upload-using-extbase-and-fal-in-typo3-6-2 在谷歌打了一段时间之后,我发现了一篇对我来说听起来很不错的文章。明天要检查一下: http//insight.helhum.io/post/85015526410/file-upload-using-extbase-and-fal-在-typo3-6-2

(just in case somebody else needs this before i could test it) (以防其他人在我测试之前需要这个)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM