1
目前我正在開發一個自定義模塊,其中包含一個表單,並提交'通過'阿賈克斯。Joomla 3.0自定義模塊:在AJAX提交的文件上傳形式
領域
<input type="file" id="file" name="file" accept="image/*" disabled="disabled" />
AJAX提交(使用JSON)
$.ajax({
type: "POST",
url: "modules/mod_custom_form/submit_form.php",
data: dataString,
dataType: "JSON",
timeout: 6000,
success: function(response) {
// on success
if (response.success === 1) {
$('#customForm').html("<div id='message'></div>");
$('#message').html("<h2>Form sent!</h2>")
.append("<p>More text.</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='checkmark' src='modules/mod_custom_form/images/check-icon.png' />");
});
}
// on failure
else {
$('#customForm').html("<div id='message'></div>");
$('#message').html("<h2>Failure.</h2>");
}
}
});
submit_form.php文件
// no direct access
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
define('JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ]);
require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php');
require_once(JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php');
$mainframe =& JFactory::getApplication('site');
// sender email
$email = '[email protected]';
$subject = 'Aanvraag';
// create the header array
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: beheer <[email protected]>";
$headers[] = "Bcc: beheer <[email protected]>";
$headers[] = "Reply-To: Recipient Name <[email protected]>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/" . phpversion();
// get all posted data and put them in variables
$bedrijfsnaam = $_POST['bedrijfsnaam'];
$_FILES = $_POST['uploaded_file'];
// create the full message
$message = 'email';
// send mail
if (mail($to, $subject, $message, implode("\r\n", $headers))) {
//save file function
getInput($_FILES);
// return message
echo json_encode(array('success' => 1));
// insert the email into the database
$database =& JFactory::getDBO();
$query = "INSERT INTO #__email_forms (mid, email, message) VALUES ('2', '[email protected]', '$message')";
$database->setQuery($query);
$database->query();
}
else {
echo json_encode(array('success' => 0));
}
我將如何實現上傳文件並保存的可能性與Ajax形式?我一直在尋找幾個小時,但到目前爲止還沒有發現任何有用的東西。
在此先感謝您的建議。
你的問題是什麼? – Toretto 2013-03-21 13:52:41
看到更新的問題:) – 2013-03-21 13:55:58
你有兩個文件在同一個文件夾?發佈submitform.php代碼 – Toretto 2013-03-21 14:00:20