1

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

“您正在将表单元素传递给startImageUpload()函数,并尝试将其作为字符串存储在您添加到imagef1_cancel element.unique id被取消。”

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

注意:未定义索引:第 22 行 /xxx/Mobile_app/cancelimage.php 中的 imagecancelname 数组(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();

    ?>
4

1 回答 1

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 设置为有用的东西并且(!)允许(永远不要相信用户输入并进行适当的验证)。

于 2012-05-18T06:53:01.943 回答