簡體   English   中英

前端圖像上傳並在typo3中建立文件參考

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

首先,我在typo3真的很新。 我使用擴展程序構建器構建了擴展程序,現在我想從前端上傳圖像。 上傳和創建文件夾功能正常。 但是typo3在上傳后不輸出文件。 根據一些谷歌搜索,我認為這與file_reference函數有關。 但是我真的堅持了這一點。 希望有人可以在這個問題上heel我。

這是我的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');
}

也許您應該看看這個存儲庫。 這是一個很好的示例,說明如何在TYPO3中使用FAL處理文件上傳。 也許有些老了,但是機制應該變得清晰起來。 https://github.com/helhum/upload_example

這是我到目前為止所擁有的:

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

因此,現在它在sys_file中上載文件和DB條目,並在my_exteension_domain_model_myObject中創建了圖像,但在可變var“ 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 ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM