如何在取消上传时识别文件字符串


How to identify the file string when upload is cancelled?

我有一个网络编程问题需要处理,如下所示:

"您正在将表单元素传递给startImageUpload()函数,并尝试将其作为字符串存储在添加到imagef1_cancel element的HTML中。这是行不通的。您需要为每个表单提供一个unique id,并使用此字符串来标识需要取消的上传。

目前,单击取消按钮时,它无法识别要从行中删除的文件。以下是var_dump($GET)print($imagecancelsql)显示的内容:

注意:未定义的索引:/xxx/Mobile_app/cancelimage.php 第 22 行中的 imagecancelnamearray(0( { } 从图像中删除,其中图像文件 = '图像文件/'

那么如何对问题进行梳理,以便识别需要取消的上传的文件字符串呢?

以下是我目前尝试解决此问题的尝试:

 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>");

最后下面是取消图像.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();
    ?>
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 设置为有用的内容并且允许 (!((永远不要相信用户输入并进行正确的验证(,您应该继续。