【问题标题】:Frontend image upload and build a file reference in typo3前端图片上传并在typo3中构建文件引用
【发布时间】:2019-12-05 17:34:13
【问题描述】:

首先,我对typo3 很陌生。 我用扩展构建器构建了一个扩展,现在我想从前端上传图像。上传和创建文件夹功能工作正常。但是typo3在上传后不输出文件。根据几个谷歌搜索,我认为它与 file_reference 函数有关。但我真的坚持这一点。希望有人能帮我解决这个问题。

这是我的 creatAction 函数:

 public function createAction(\Demian\Inserateextension\Domain\Model\myObject $newObject)
    {


    $chiffre = $_POST['tx_myplugin']['myObject']['chiffre'];
    $newImagePath = 'inserate/'.$chiffre;


    if ($_FILES['tx_myplugin']['name']['gallerie'][0]) {


        $tmpName = $_FILES['tx_myplugin']['name']['gallerie'][0];
        $tmpFile  = $_FILES['tx_myplugin']['tmp_name']['gallerie'][0];

        $storageRepository = $this->objectManager->get('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
        $storage = $storageRepository->findByUid('1'); //this is the fileadmin storage

        //build the new storage folder
        $targetFolder = $storage->createFolder($newImagePath);

     //Upload the file
        $movedNewFile = $storage->addFile($tmpFile, $targetFolder, $tmpName);



}

    $this->myObjectRepository->add($newObject);
    $this->redirect('list');
}

【问题讨论】:

    标签: image-upload typo3-9.x filereference fal


    【解决方案1】:

    也许你应该看看这个存储库。这是一个很好的例子,如何在 TYPO3 中使用 FAL 处理文件上传。 也许有点旧,但机制应该变得清晰。 https://github.com/helhum/upload_example

    【讨论】:

    • 谢谢!我会试试的
    • 如果您使用typo3_9,则不应使用TYPO3 6.2
    【解决方案2】:

    这是我目前所拥有的:

    公共函数 createAction(\Demian\Inserateextension\Domain\Model\myObject $newObject) { $chiffre = $_POST['tx_myplugin']['myObject']['chiffre']; $newImagePath = '插入/'.$chiffre; if ($_FILES['tx_myplugin']['name']['gallerie'][0]) { $tmpName = $_FILES['tx_myplugin']['name']['gallerie'][0]; $tmpFile = $_FILES['tx_myplugin']['tmp_name']['gallerie'][0]; $storageRepository = $this->objectManager->get('TYPO3\\CMS\\Core\\Resource\\StorageRepository'); $storage = $storageRepository->findByUid('1'); //这是文件管理存储 //建立新的存储文件夹 $targetFolder = $storage->createFolder($newImagePath); //上传文件 $movedNewFile = $storage->addFile($tmpFile, $targetFolder, $tmpName); } $this->myObjectRepository->add($newObject); $this->redirect('list'); } $this->buildRelations($newObject->getUid(), $movedNewFile, 'gallerie', 'tx_myplugin', $storagePid); 私有函数 buildRelations($newStorageUid, $file, $field, $table, $storagePid) { $数据 = 数组(); $data['sys_file_reference']['NEW1234'] = 数组( 'uid_local' => $file->getUid(), 'uid_foreign' => $newStorageUid, 'tablenames' => $table, '字段名' => $字段, 'pid' => $storagePid, 'table_local' => 'sys_file', ); $data[$table][$newStorageUid] = array('image' => 'NEW1234'); /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $tce */ $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler'); // 创建 TCE 实例 $tce->start($data, array()); $tce->process_datamap(); }

    所以现在它在 sys_file 中上传文件和数据库条目,并在 my_exteension_domain_model_myObject 中创建,但图像路径仍未显示在流体变量“myObject.gallerie.originalResource.publicUrl”中。 “l10n_diffsource”列也为空,但应该类似于:

    a:7{s:16:"sys_language_uid";N;s:6:"hidden";N;s:5:"title";N;s:7:"chiffre";N; s:8:"画廊";N;s:9:"st…

    【讨论】:

      猜你喜欢
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-23
      • 2016-09-30
      • 1970-01-01
      • 2017-11-29
      相关资源
      最近更新 更多