我正在使用实时预览创建一个 php/JQuery 头像上传器,它似乎工作正常,但由于某种原因,在表单发送到的 /avatar.php 文件上,信息没有被发送或处理(值没有从 Javascript 更新)。这是我的 HTML / Javascript:
<script type="text/javascript">
$(function () {
$('#previewAvatar').imgAreaSelect({ x1: 10, y1: 10, x2: 210, y2: 210, aspectRatio: '1:1', maxWidth: 292, maxHeight: 292, handles: true, show : true });
});
</script>
<form id="avatarForm" method="post" enctype="multipart/form-data" action="php/avatar.php">
<div class="formSection">
<div class="formRight">
<div>
<div class="formTag">Avatar</div>
<div class="formSubTag nameStatus errorStatus">Bigger than 300 x 300px but less than 2400k</div>
<div id="previewOldAvatarHolder">
<img id="previewOldAvatar" src="uploads/avatars/<?php echo $youravatar; ?>" />
<img id="previewAvatar" src="#" />
</div>
<input type="hidden" id="x" name="x" value="" />
<input type="hidden" id="y" name="y" value="" />
<input type="hidden" id="w" name="w" value=""/>
<input type="hidden" id="h" name="h" value="" />
<input type="file" id="avatarupload" name="avatarupload" />
</div>
<div class="formButtonHolder">
<div class="formButton">
<input type="hidden" id="id" name="id" value="<?php echo $yourid; ?>" />
<input type="hidden" id="avatar" name="avatar" value="<?php echo $youravatar; ?>" />
<input type="submit" id="avatarButton" value="Click To Update »" /><div class="avatarValidation validation"></div>
<div class="clearLeft"></div>
</div>
</div>
</div>
<div class="clearLeft"></div>
</div>
</form>
<script type="text/javascript">
function addavatar(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#previewAvatar').attr('src', e.target.result);
$('#previewAvatar').imgAreaSelect({
onSelectChange: preview,
onSelectEnd: function (img, selection) {
$('input[name="x"]').val(selection.x1);
$('input[name="y"]').val(selection.y1);
$('input[name="w"]').val(selection.width);
$('input[name="h"]').val(selection.height);
}
});
}
reader.readAsDataURL(input.files[0]);
}
}
$("#avatarupload").change(function(){
$('#previewOldAvatar').hide();
addavatar(this);
});
</script>
这是我要发送到的 PHP 文件:
$extension = end(explode(".", $_FILES["avatarupload"]["name"]));
$id = mysqli_real_escape_string($con, $_POST["id"]);
$time = time();
$avatarid= time().'-'.mt_rand(1000, 9999);
$avatar = mysqli_real_escape_string($con, $_POST["avatar"]);
$w= mysqli_real_escape_string($con, $_POST["w"]);
$h= mysqli_real_escape_string($con, $_POST["h"]);
$x= mysqli_real_escape_string($con, $_POST["x"]);
$y= mysqli_real_escape_string($con, $_POST["y"]);
$rw = 292;
$rh = 292;
$path = "../uploads/avatars/";
$unlink = "$path$avatar";
$newimage = "$path$newavatar";
$wratio = ($rw/$w); // GETTING ERROR (Warning: Division by zero in ...)
$hratio = ($rh/$h); // GETTING ERROR (Warning: Division by zero in ...)
$newW = ceil($w * $wratio);
$newH = ceil($h * $hratio);
$newimg = imagecreatetruecolor($newW,$newH);
$ext=$extension;
谁能看到这里可能出现的问题?