[TYPO3-english] Upload image with FAL from Front End in Typo3 7

Maunil Prajapati mp at webofficeindia.com
Fri Apr 15 09:19:26 CEST 2016


Hello All

I want to upload Multiple Image from Front End but there is problem. Can
you please tell me what

is the correct way to upload multiple images from front end. currently i
used manually  code to

insert images with FAL . Please tell me what is the correct way to
implement multiple image with FAL. please tell me step to step information
regarding this . i hope i will get my result.

my code is like this
-----------------------------------------------------------------------------------
$files = $this->uploadFile($file['name'], $file['type'], $file['tmp_name'],
$file['size']);

$file['name'] = $_FILES['photo']['name'];
$fileStored = $file['name'];
 $img_count = 1;
foreach ($fileStored as $key => $value) {
$sys_file_imgtable = "sys_file";
$uploadPath = '/user_upload/postproperty/'.$value;
$sys_file_fields_values = array(
'tstamp' => $GLOBALS['EXEC_TIME'],
'identifier' => $uploadPath,
'mime_type' => $_FILES['propertyphoto']['type'][$key],
'name' => $value
);
$falimag = $this->getDBHandle()->exec_INSERTquery($sys_file_imgtable,
$sys_file_fields_values, $no_quote_fields = false);

$last_sys_file_InsertId = $this->getDBHandle()->sql_insert_id($falimag);
$sys_reference_imgtable = "sys_file_reference";
$Sys_reference_fields_values = array(
'crdate' => $GLOBALS['EXEC_TIME'],
'tstamp' => $GLOBALS['EXEC_TIME'],
'uid_local' => $last_sys_file_InsertId,
'tablenames' => 'tx_milkat_domain_model_milkat',
'pid' => $pid ,
'sorting_foreign' =>$img_count,
'uid_foreign' => $lastInsertId,
'fieldname' =>'image',
'table_local' =>'sys_file'
);
$falimag = $this->getDBHandle()->exec_INSERTquery($sys_reference_imgtable,
$Sys_reference_fields_values, $no_quote_fields = false);
$img_count++;
}





protected function uploadFile($name, $type, $temp, $size) {

if($size > 0) {
$basicFileFunctions =
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_basicFileFunctions');
$uploadPath = 'fileadmin/user_upload/postproperty';
foreach ($name as $key => $value) {
$valueofimg = $basicFileFunctions->cleanFileName($value);
$uploadPath
=\TYPO3\CMS\Core\Utility\PathUtility::getCanonicalPath($uploadPath);
$uniqueFileName = $basicFileFunctions->getUniqueName($valueofimg,
$uploadPath);
$movetouploded = move_uploaded_file($temp[$key], $uniqueFileName);
$returnValue = basename($uniqueFileName);
}
}
return $returnValue;

}
--


More information about the TYPO3-english mailing list