我有一個Web編程的問題,我需要處理的是以下:上傳被取消時如何識別文件字符串?
「你的表單元素傳遞給startImageUpload()
功能,並試圖將其存儲作爲HTML添加到imagef1_cancel element
字符串。這是行不通的,你需要給每個表格一個unique id
,並用這個字符串來標識需要取消的上傳。「
目前,當點擊取消按鈕時,它無法識別想要從行中刪除的文件。下面是什麼var_dump($GET)
和print($imagecancelsql)
被示出:
說明:未定義指數:imagecancelname在/xxx/Mobile_app/cancelimage.php上線22 陣列(0){} DELETE FROM圖片WHERE鏡像文件= '的圖像文件中/'
那麼如何解決這個問題,以便它可以識別需要取消上傳的文件字符串?
下面是試圖解決這個我目前的嘗試:
var sourceImageForm;
function startImageUpload(imageuploadform, imagecancelname){
$(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');
$(imageuploadform).find('.imagef1_cancel').css('visibility','visible');
$(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden');
sourceImageForm = imageuploadform;
/*The above would show and hide elements within the form the file is being uploaded.
For example if I have three forms and the second form is uploading a file, then it
shows and hides the elements within the second form only */
$(imageuploadform).find('.imagef1_cancel').html('<div><button type="button" class="imageCancel" id="image_cancel_' + imagecancelname + '">Cancel</button></div>').find(".imageCancel").on("click", function(event) {
$.ajax("cancelimage.php?imagecancelname=" + $(this).attr('id').slice(13));
});
return true;
}
下面是表單代碼:
var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return startImageUpload(this);' class='imageuploadform' >" +
"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'></p>" +
"<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>");
最後下面是它是假設刪除分貝cancelimage.php行包含文件名:
<?php
// ... connected to DB
$image_cancel = '';
if (isset($_GET["imagecancelname"])) { $image_cancel = $_GET["imagecancelname"]; }
$image_cancel = $_GET["imagecancelname"];
$imagecancelsql = "
DELETE FROM Image
WHERE ImageFile = 'ImageFiles/".mysql_real_escape_string($image_cancel)."'
";
print $imagecancelsql;
mysql_close();
?>
嗨,它給了我相同的通知,我上面更新了代碼,顯示了當前代碼現在看起來像什麼 – user1394925
是的,因爲你仍然留下這一行:$ image_cancel = $ _GET [「imagecancelname」];在你的代碼中(沒有isset()的行) – djot
哦,是的,我是個傻瓜。乾杯:) – user1394925