简体   繁体   English

前端图像上传并在typo3中建立文件参考

[英]Frontend image upload and build a file reference in typo3

First, im really new at typo3. 首先,我在typo3真的很新。 I build a extension with extension builder, and now i want to upload images from the Frontend. 我使用扩展程序构建器构建了扩展程序,现在我想从前端上传图像。 The upload and the creating Folder function is working fine. 上传和创建文件夹功能正常。 But typo3 doesnt output the file after upload. 但是typo3在上传后不输出文件。 According to several google searches i think it has to do with the file_reference function. 根据一些谷歌搜索,我认为这与file_reference函数有关。 But im really stuck on this. 但是我真的坚持了这一点。 Hope somebody can heelp me on this. 希望有人可以在这个问题上heel我。

Heres my creatAction Funnction: 这是我的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');
}

Maybe you should have a look in this repository. 也许您应该看看这个存储库。 It is a good example how to handle file uploads with FAL in TYPO3. 这是一个很好的示例,说明如何在TYPO3中使用FAL处理文件上传。 Maybe a little old, but the mechanics should become clear. 也许有些老了,但是机制应该变得清晰起来。 https://github.com/helhum/upload_example https://github.com/helhum/upload_example

This is what i have so far: 这是我到目前为止所拥有的:

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');
}



$this->buildRelations($newObject->getUid(), $movedNewFile, 'gallerie', '    tx_myplugin', $storagePid);

private function buildRelations($newStorageUid, $file, $field, $table, $storagePid) {

        $data = array();
        $data['sys_file_reference']['NEW1234'] = array(
            'uid_local' => $file->getUid(),
            'uid_foreign' => $newStorageUid, 
            'tablenames' => $table, 
            'fieldname' => $field, 
            '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'); // create TCE instance
        $tce->start($data, array());
        $tce->process_datamap();
    }

So now it uploads the file and a DB entry in sys_file, and in my_exteension_domain_model_myObject is created but the image path is still not showin in the fluid var "myObject.gallerie.originalResource.publicUrl". 因此,现在它在sys_file中上载文件和DB条目,并在my_exteension_domain_model_myObject中创建了图像,但在可变var“ myObject.gallerie.originalResource.publicUrl”中仍未显示图像路径。 Also the column "l10n_diffsource" is null, but shoud be something like: 此外,列“ l10n_diffsource”为空,但应类似于:

a:7{s:16:"sys_language_uid";N;s:6:"hidden";N;s:5:"title";N;s:7:"chiffre";N;s:8:"gallerie";N;s:9:"st… 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 ...

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

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