将多部分编码添加到 xml 定义中的表单后:
<?xml version="1.0" encoding="utf-8"?>
<form enctype="multipart/form-data">
<fieldset>
你会发现一个数组“files”,它看起来像:(这里“pdf”是字段名)
'name' => array ( 'pdf' => '', ),
'type' => array ( 'pdf' => '', ),
'tmp_name' => array ( 'pdf' => '', ),
'error' => array ( 'pdf' => 4, ),
'size' => array ( 'pdf' => 0, ), )
空时,和
'name' => array ( 'pdf' => '8.jpg', ),
'type' => array ( 'pdf' => 'image/jpeg', ),
'tmp_name' => array ( 'pdf' => '/tmp/phpk1fDmB', ),
'error' => array ( 'pdf' => 0, ),
'size' => array ( 'pdf' => 26975, ),
满的时候。临时文件夹是 php tmp 文件夹,而不是 Joomla 的。您可以根据需要调整此功能:
private function getFile($key,$destinationFolder) {
/**
* now let's process uploads: the array files contains a key "$key" which is the key name.
* we need to copy the files uploaded
* (if any are there and if they match the field filter = pdf)
* and set the data->pdf to its new path.
* */
$file = JRequest::getVar('jform', array(), 'files', 'array');
if ($file['error'][$key]!="0") {
error_log('no files uploaded, exiting now');
return "";
}
//error_log('OFFER FOUND FILES '.var_export($file,true));
$tempName = $file['tmp_name'][$key];
$tempFullPath = ini_get('upload_tmp_dir').$tempName;
$type = $file['type'][$key];
$name = $file['name'][$key];
//error_log('DATA FOUND: '. "temp: $tempName , type: $type, name: $name");
if (file_exists($tempFullPath))
{
if (mkdir(JPATH_SITE.$destinationFolder,0755,true)) {
if (copy($source = $tempFullPath, $dest = JPATH_SITE.$destinationFolder."/".$name)) {
return $destinationFolder."/".$name;
} else
{
error_log('could not copy '. "$source to $dest");
}
} else {
error_log('could not create folder '. JPATH_SITE.$destinationFolder);
}
return "";
} else {
error_log('FILE NOT FOUND: '. $tempFullPath);
}
error_log 用于将信息转储到服务器错误日志,您可以将其删除并用适当的异常替换它。