Typo3: How to upload a file and create a file reference?

ぃ、小莉子 提交于 2019-12-06 01:24:50

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

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

(just in case somebody else needs this before i could test it)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!