0
ファイルをアップロードする特定のモジュールを作成しようとしています。モジュールを使用してjoomlaにファイルをアップロードする
私はこのコードを使用しています:
クライアント側:
<?php
// No direct access
defined('_JEXEC') or die; $resposta =""; ?>
<form name="upload" method="post" enctype="multipart/form-data">
<input type="file" name="file_upload" />
<input type="submit" name="submit_file" value="submit_file"/>
<input type="text" name="resposta" value=<?php echo $resposta; ?> />
</form>
マイモジュール:
<?php
defined('_JEXEC') or die;
include_once __DIR__ . '/helper.php';
//trigger the event
// Instantiate global document object
defined('_JEXEC') or die;
// Include the syndicate functions only once
require_once dirname(__FILE__) . '/helper.php';
$resposta = ModuploadfileHelper::getuploadfile($params);
require JModuleHelper::getLayoutPath('mod_upload_file');
?>
マイヘルパー:
<?php
class ModuploadfileHelper {
public static function getuploadfile($params) {
/*
* File upload example
*/
//Retrieve file details from uploaded file, sent from upload form
$file = JFactory::getApplication()->input->get('file_upload');
//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;
if(!JFolder::exists($dest))
{
$mode = 0755;
JFolder::create($dest, $mode);
}
$resposta = null;
//First check if the file has the right extension, we need jpg only
if (strtolower(JFile::getExt($filename)) == 'jpg')
{
// TODO: Add security checks
if (JFile::upload($src, $dest))
{
$resposta = "Sucesso ao arquivar a imagem";
}
else
{
$resposta = "Insucesso ao arquivar a imagem";
}
}
else
{
$resposta = "O ficheiro não é uma imagem";
}
return $resposta;
}
}
?>
最初の質問は:何かをしますこの作品のように? 2番目の質問:モジュールを動作させるためのトリガーの実行方法
13番目の質問:モジュールをajaxに渡すにはどうすればいいですか?
モジュールのコード: 私はこのような何かを持っている
<?php
defined('_JEXEC') or die;
include_once __DIR__ . '/helper.php';
// Instantiate global document object
defined('_JEXEC') or die;
// Include the syndicate functions only once
require_once dirname(__FILE__) . '/helper.php';
$resposta = ModuploadfileHelper::getuploadfile($params);
defined('_JEXEC') or die;
include_once __DIR__ . '/helper.php';
// Instantiate global document object
$doc = JFactory::getDocument();
$js = <<<JS
(function ($) {
$(document).on('click', 'input[type=submit]', function() {
formdata = new FormData();
var file = this.files[0];
formdata.append("image", file);
$.ajax({
type : 'POST',
data : request,
success: function (response) {
$('.search-results').html(response);
}
});
return false;
});
})(jQuery)
JS;
$doc->addScriptDeclaration($js);
require JModuleHelper::getLayoutPath('mod_upload_file');
?>
ヘルプ私にしてください。
私はいくつかの研究を行ってからしているが、どのようなIいくつかのブラウザはajaxを介してフォームを送信することをサポートしていません。私はファイルのアップロードを簡単にしたいと思います。 –
どのブラウザが表示されないのですか?しかし、Ajaxが必要ない場合は、問題が実際に表示されません。フォームがポストされるページにモジュールが公開される必要があるため、トリガーされます$ _FILES変数に作用することができます。 JFactory :: getApplication() - >入力 - >ファイル - > get( 'file_upload'); – JulienV
さらに良いことに、あなたは 'com_ajax'モジュールのurlへの定期的な投稿要求をして、アップロードが処理されるとリダイレクトを行うことさえできます。 – JulienV