我使用jqueryForm和imgAreaSelect插件上传图片,用imgAreaSelect插件裁剪然后保存。问题是我不知道如何在上传后获取文件名。当然我知道它是如何制作并知道来源的,但不能从上传php脚本访问变量。
$(document).ready(function () {
$(".uploadform").ajaxForm({
target: '#viewimage',
beforeSubmit: function () {
$("#viewimage").html('Uploading...');
},
success: function () {
$('img').imgAreaSelect({
aspectRatio: '166:90',
minHeight: 90,
minWidth: 166,
onSelectEnd: function (img, selection) {
$('input[name="x1"]').val(selection.x1);
$('input[name="y1"]').val(selection.y1);
$('input[name="x2"]').val(selection.x2);
$('input[name="y2"]').val(selection.y2);
$('input[name="width"]').val(selection.x2-selection.x1);
$('input[name="height"]').val(selection.y2-selection.y1);
$('input[name="source"]').val($(this));
}});
}
});
});
所以问题是我如何从ajax使用的脚本中获取变量来访问上传的图像源?
UPD: Php脚本:
$imagename = md5(uniqid().time()).".".$extension;
$tmp = $_FILES['imagefile']['tmp_name'];
if (move_uploaded_file($tmp, $filepath . $imagename)) {
echo '<img class="preview" alt="" src="'.$filepath.'/'.
$imagename .'" />';
答案 0 :(得分:0)
名称将在
中$_FILES['imagefile']['name']
答案 1 :(得分:0)
这对我有帮助
$(document).ready(function () {
$(".uploadform").ajaxForm({
target: '#viewimage',
beforeSubmit: function () {
$("#viewimage").html('Uploading...');
// showRequest;
},
success: function () {
$('img').imgAreaSelect({
// showResponse();
aspectRatio: '166:90',
minHeight: 90,
minWidth: 166,
onSelectEnd: function (img, selection) {
$('input[name="x1"]').val(selection.x1);
$('input[name="y1"]').val(selection.y1);
$('input[name="x2"]').val(selection.x2);
$('input[name="y2"]').val(selection.y2);
$('input[name="width"]').val(selection.x2-selection.x1);
$('input[name="height"]').val(selection.y2-selection.y1);
$('input[name="source"]').val($('img').attr( 'src' ));
}});
}
});
});