私はこれをかなり長い間探していましたが、私のニーズに合った解決策を見つけることができませんでした. Joomla 2.5 のモジュールを開発しています。ユーザーがモジュール構成でバックエンドから画像/任意のファイルタイプをアップロードできるようにする機能が必要です。
質問 : joomla モジュールにファイル アップロード用のフィールドを追加するにはどうすればよいですか。
ありがとう!
joomla docs からの単なるサンプル:
<?php
//Retrieve file details from uploaded file, sent from upload form
$file = JRequest::getVar('file_upload', null, 'files', 'array');
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name']);
//Set up the source and destination of the file
$src = $file['tmp_name'];
$dest = JPATH_COMPONENT . DS . "uploads" . DS . $filename;
//First check if the file has the right extension, we need jpg only
if ( strtolower(JFile::getExt($filename) ) == 'jpg') {
if ( JFile::upload($src, $dest) ) {
header("Location: http://".$_SERVER["HTTP_HOST"]."/administrator"); Redirect to a page of your choice
} else {
echo "error !"; //Redirect and throw an error message
}
} else {
echo "Wrong extension !"; //Redirect and notify user file is not right extension
}
?>
より詳細な情報と完全な例: http://docs.joomla.org/How_to_use_the_filesystem_package
HTML フォームには次の要素を含める必要があることに注意してください。
enctype="multipart/form-data"
そうしないと、joomla 関数で結果が得られません!