当用户单击“取消”按钮时,我正在尝试检索已取消上传的文件的文件名。问题是我相信我使用的方法 (var image_file_name" 没有检索已取消的文件名。有谁知道检索已取消文件名的解决方案?
下面是控制“取消”按钮的表单代码和 Javascript 函数:
var $fileImage = $("<form action='imageupload.php'
method='post'enctype='multipart/form-data' target='upload_target' onsubmit='return
startImageUpload(this);' class='imageuploadform' ><label>" +
"Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/>
<br/><label class='imagelbl'>" +
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload'/>
</label>" +
"</p><p class='imagef1_cancel' align='center'><label>" +
"<input type='button' name='imageCancel' class='imageCancel' value='Cancel'/>
</label>" +
"</p><p class='listImage' align='left'></p>" +
"<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>")
...
var _cancelimagecounter = cancelimagecounter;
$(".imageCancel").click(function() {
var image_file_name = <?php echo json_encode($image_file_name); ?>;
jQuery.ajax("cancelimage.php?fileImage=" + image_file_name)
.done(function(data) {
$(".imagemsg" + _cancelimagecounter).html(data);
});
return stopImageUpload();
});
下面是 cancelimage.php 脚本,它使用 $GET 方法从 var image_file_name 获取文件名:
<?php
...
$image_file_name = $_GET["fileImage"];
echo "File Upload was Canceled";
$imagecancelsql = "DELETE FROM Image
WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($image_file_name)."'";
mysql_query($imagecancelsql);
mysql_close();
?>