I use jqueryForm and imgAreaSelect plugins for upload an image, crop it with imgAreaSelect plugin and then save. The problem is i don't know how to get file name after uploading. Sure i know how it being made and know the source, but can't access variable from upload php script.
$(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));
}});
}
});
});
So the question is how i can get variable from script that used by ajax to access source to image uploaded?
UPD: Php script:
$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 .'" />';
the name will be in
$_FILES['imagefile']['name']
Well this is something that helps me
$(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' ));
}});
}
});
});