[TYPO3-mvc] <f:form.upload and how to upload files?
Steffen Ritter
info at rs-websystems.de
Sat Aug 7 09:32:57 CEST 2010
Am 07.08.2010 00:18, schrieb Braulio J. Solano-Rojas:
> Hi.
>
> El 02/08/2010 03:36 a.m., Daniel Dimitrov escribió:
>> Ok, I found the problem myself - my form was missing an
>> enctype="multipart/form-data"...
>
> Did it work for you?
>
> Because I have the same encoding type, however my $_FILES array gets
> overwritten with extbase objects (at least that's what my debugger shows
> me).
>
Have a look at "how" an extbase upload could look :P
http://sherpas.nezzgo-dev.de/faq.html?no_cache=1 (try uploading pngs)
You need: an Upload Handling action, an upload handliner function (both
my be in an abstract controller), a second pagetype handling your upload
and an combination of swfupload and jquery ui (progressbar) and a
slightly modfied jquery fancybox :):
An Example Handler for videos (filled some variables):
/**
*
*/
public function handleUploadAction() {
$newFile = $this->handleUpload('swfUpload',
'/uploads/rsmysherpasprojects/videos/', 'avi,mov,mpg,mpeg,flv,png,jpg',
1000 * 1024 * 1024);
if ((string)intval($newFile) == (string)$newFile) {
$this->throwStatus(400 + $newFile);
} else {
$video =
t3lib_div::makeInstance('Tx_Rsmysherpasprojects_Service_Factory_VideoFactory')->createVideo(PATH_site
. '/uploads/rsmysherpasprojects/videos/' . $newFile);
if($video !== NULL) {
t3lib_div::makeInstance('Tx_Rsmysherpasprojects_Domain_Repository_VideoRepository')->add($video);
//$project->setVideo($video);
Tx_Extbase_Dispatcher::getPersistenceManager()->persistAll();
return $video->getUid();
} else {
$this->throwStatus(500);
}
}
return 'ende';
}
The general Upload handler:
protected function handleUpload($property, $uploadDir, $types =
'jpg,gif,png', $maxSize = '1000000') {
$data = $_FILES['tx_' .
strtolower($this->request->getControllerExtensionName()) . '_' .
strtolower($this->request->getPluginName())];
if(is_array($data) && count($data)>0) {
$propertyPath = t3lib_div::trimExplode('.',$property);
$namePath = $data['name'];
$tmpPath = $data['tmp_name'];
$sizePath = $data['size'];
foreach($propertyPath as $segment) {
$namePath = $namePath[$segment];
$tmpPath = $tmpPath[$segment];
$sizePath = $sizePath[$segment];
}
if($namePath !== NULL && $namePath !== '') {
$fileArray = array(
'name' => $namePath,
'tmp' => $tmpPath,
'size' => $sizePath,
);
} else {
return 1;
}
} else {
return 0;
}
if($fileArray['size'] > $maxSize) {
return 2;
}
$fileInfo = pathinfo($fileArray['name']);
if(!t3lib_div::inList($types, strtolower($fileInfo['extension']))) {
return 3;
}
if(file_exists(PATH_site . $uploadDir . $fileArray['name'])) {
$fileArray['name'] = $fileInfo['filename'] . '-' . time() . '.' .
$fileInfo['extension'];
}
if(t3lib_div::upload_copy_move($fileArray['tmp'], PATH_site .
$uploadDir . $fileArray['name'])) {
return $fileArray['name'];
} else {
return 4;
}
And:
an AJAX Page-Type:
ajax = PAGE
ajax {
typeNum = 735
config {
no_cache = 1
disableAllHeaderCode = 1
sendCacheHeaders = 1
}
10 < tt_content.list.20.rsmysherpasprojects_pi1
}
More information about the TYPO3-project-typo3v4mvc
mailing list