マルチパート エンコーディングを 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, ),
満タン時。一時フォルダーは、Joomla のフォルダーではなく、php tmp フォルダーです。この関数をニーズに合わせて調整できます。
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 は、サーバー エラー ログに情報をダンプするために使用されます。これを削除して、適切な例外に置き換えることができます。