我无法访问php.ini文件,因此我需要在上传的图像到达服务器端之前对其进行压缩。我还需要同时处理许多文本输入(注释,组名,事件名)。
我的HTML如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Uploads</title>
<link type="text/css" href="style.css">
</head>
<body>
<div class="container">
<form onClick="return submit_form_up()" enctype="multipart/form-data" id="up-form">
<input type="file" name="img" id="img" accept="image/*"><br>
<textarea name="text" cols="40" rows="4" placeholder="Enter text here" id="comment"></textarea><br>
<select name = "group_name" id="gr_name">
<optgroup label="Group_name">
<?php
include ('conn.php');
$sql = "SELECT * FROM groups ORDER BY id ASC";
$result = mysqli_query($conn , $sql);
while($row = mysqli_fetch_array($result , MYSQLI_ASSOC))
{
echo '<option value="' . $row['group_name'] . '">' . $row['group_name'] . '</option>';
}
?>
</optgroup>
</select>
<select name="event_name" id="ev_name">
<optgroup label="Event_name">
<?php
include ('conn.php');
$sql = "SELECT * FROM event_name ORDER BY id ASC";
$result = mysqli_query($conn , $sql);
while($row = mysqli_fetch_array($result , MYSQLI_ASSOC))
{
echo '<option value="' . $row['events'] . '">' . $row['events'] . '</option>';
}
?>
</optgroup>
</select>
<br>
<button type="submit" name="sub-button" id="sub-button">Submit</button>
</form>
</div>
<script type="text/javascript" src="updates_js.js"></script>
</body>
</html>
当前的jquery文件看起来像这样,请你帮我解释一下如何不仅要压缩图像一定程度,还要正确传输必要的数据
$(document).ready(function (){
"use strict";
var filedata = $('#img').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
alert(form_data);
$.ajax({
url: 'upload.php', // point to server-side PHP script
dataType: 'text', // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(php_script_response){
alert(php_script_response); // display response from the PHP script, if any
}
});
});