我想發佈文件和按鈕的值,並在PHP中處理它。jquery發佈文件和按鈕的值,並從腳本獲得響應
的問題是在我的PHP腳本ha2e.php
條件if (isset($_FILES['file'])) {}
總是過得false
HTML:
<div id="htmlar2en" style="text-align:center">
<div class="container">
<div style="text-align:center">
<h1> Arabic to English HTML </h1>
<form method="post" enctype="multipart/form-data" target="iframe4" id = "htmla2e">
*.XLSX <input type="file" name="file" /> <input type="submit" id="submit4" name="submit4" value="HTML Arabic to English" />
</form>
<iframe name="iframe4" id="iframe4" src="" style="display:none" ></iframe>
</div>
</div>
</div>
的jQuery:
$(document).ready(function() {
var extra_data = "This is more stuff to send";
var Bvalue = $(this).attr("value");
$('#submit4').click(function() {
$.ajax({
type: "POST",
url: "he2a.php",
data: {'form': $("#htmla2e").serialize(), 'other': extra_data, 'submit4': Bvalue},
success: function(msg) {
alert("Form Submitted: " + msg);
}
});
});
});
PHP:
<?php
if (isset($_FILES['file'])) {
header('Content-Type: text/html; charset=UTF-8');
echo '<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />';
require_once "simplexlsx.class.php";
require '../../Arabic.php';
$Arabic = new I18N_Arabic('Transliteration');
$xlsx = new SimpleXLSX($_FILES['file']['tmp_name']);
echo "df";
echo '<table border="1" cellpadding="3" style="border-collapse: collapse">';
$eng = array();
list($cols,) = $xlsx->dimension();
foreach($xlsx->rows() as $k => $r) {
// if ($k == 0) continue; // skip first row
echo '<tr>';
for($i = 0; $i < $cols; $i++)
{
if ($_POST['submit3'] == 'HTML English to Arabic')
{
$temp = $Arabic->en2ar($r[$i]);
}
else if ($_POST['submit4'] == 'HTML Arabic to Englis')
{
$temp = $Arabic->ar2en($r[$i]);
}
else
continue;
echo '<td>'.((isset($r[$i])) ? $temp : ' ').'</td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
請檢查此演示並下載並修改它。 http://www.sanwebe.com/downloads/18-ajax-file-upload –
在這裏閱讀http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery = >如果您需要廣泛的瀏覽器支持,幾乎無法上傳Ajax文件。 –