我使用jqueryForm和imgAreaSelect插件上傳圖像,使用imgAreaSelect插件裁剪,然後保存。問題是我不知道如何獲得上傳後的文件名。當然,我知道它是如何製作的,知道源代碼,但不能從上傳的PHP腳本訪問變量。ajax上傳後獲取文件名
$(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 .'" />';
請張貼的PHP腳本。你應該能夠在你的php腳本的$ _FILES []變量中找到任何文件。 – ksealey
在主帖中發佈了php腳本。 – Bullwinkle