2016-11-19 70 views
0

我有一個擴展名,用戶可以在前端上傳一些圖像到他們的前端配置文件。圖片上傳和保存到用戶個人資料工作正常,我的用戶下面的代碼 - 但是有沒有簡單的方法來添加標題,替代和描述呢?TYPO3 FAL上傳前端添加標題,備選和說明

感謝您的幫助! Martin

/** @var \TYPO3\CMS\Core\Resource\StorageRepository $storageRepository */ 
     $storageRepository = $this->objectManager->get('TYPO3\CMS\Core\Resource\StorageRepository'); 
     /** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */ 
     $storage = $storageRepository->findByUid('1'); 

     #$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository'); 
     #$storage   = $storageRepository->findByUid(1); # Fileadmin = 1 
     #$saveFolder  = $storage->getFolder($this->settings['uploadFolder']); 

     $fileData = array(); 
     $fileData['name'] = $_FILES['tx_key_datenwartung']['name']['logo'][0]; 
     $fileData['type'] = $_FILES['tx_key_datenwartung']['type']['logo'][0]; 
     $fileData['tmp_name'] = $_FILES['tx_key_datenwartung']['tmp_name']['logo'][0]; 
     $fileData['size'] = $_FILES['tx_key_datenwartung']['size']['logo'][0]; 


     // this will already handle the moving of the file to the storage: 
     $newFileObject = $storage->addFile(
       $fileData['tmp_name'], $saveFolder, $userUid.'_'.$fileData['name'] 
     ); 
     $newFileObject = $storage->getFile($newFileObject->getIdentifier()); 
     #$newFile = $this->fileRepository->findByUid($newFileObject->getProperty('uid')); 

     $newFile = $newFileObject->getUid(); 

     $persistenceManager = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager'); 
     $persistenceManager->persistAll(); 

     /** @var \Vendor\Myextension\Domain\Model\FileReference $newFileReference */ 
     $newFileReference = $this->objectManager->get('Ven\Key\Domain\Model\FileReference'); 
     $newFileReference->setFile($newFile); 


     $user->addLogo($newFileReference); 
+1

**注意:**'$ fileData ['type']'是用戶提交的數據。你應該驗證文件內容是否與MIME類型有關,並檢查它是否被允許。否則,用戶可以上傳可執行文件(PHP,Perl,其他)來劫持系統。 –

回答

0

....可以自己解決。只需添加二傳手模型,並添加文字:

/** 
* Set alternative 
* 
* @param \xx\yy\Domain\Model\File $file 
*/ 
public function setAlternative($alternative) { 
    $this->alternative = $alternative; 
} 
和控制器:

$ newFileReference-> setAlternative( '圖像的替代文字');