我有一个我需要处理的网络编程问题,如下所示:
“您正在将表单元素传递给startImageUpload()
函数,并尝试将其作为字符串存储在您添加到imagef1_cancel element
的HTML中。这不起作用。您需要给每个形成unique id
,并使用此字符串来标识需要取消的上传。“
当点击取消按钮时,它无法识别要从行中删除的文件。以下是var_dump($GET)
和print($imagecancelsql)
显示的内容:
注意:未定义的索引:第22行的/xxx/Mobile_app/cancelimage.php中的imagecancelname array(0){} DELETE FROM Image WHERE ImageFile ='ImageFiles /'
那么如何解决问题,以便识别需要取消的上传文件字符串?
以下是我目前尝试解决此问题的尝试:
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,它假设删除包含文件名的db行:
<?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();
?>
答案 0 :(得分:1)
Notice: Undefined index: imagecancelname
在检查此GET索引是否存在时,您可以删除此通知:
$image_cancel = '';
if (isset($_GET["imagecancelname"])) { $image_cancel = $_GET["imagecancelname"]; }
// This line is only asking what that underscore is good for (typo?)
// $image_cancel_ = $_GET["imagecancelname"];
^
|
? ? ?
稍后您应该继续,如果$ image_cancel设置为有用且允许(!)(永远不要信任用户输入并进行适当的验证)。