简体   繁体   中英

How to be able to retrieve the name of the file that has been cancelled?

I am trying to retrieve the file name of the file for which an upload has been cancelled when the user clicked on the "Cancel" button. The problem is that I believe the method I am using (var image_file_name" is not retrieving the name of that file which has been cancelled. Does anyone know a solution to retrieve the name of the file which has been canceled?

Below is the form code and Javascript function which controls the "Cancel" button:

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

});     

Below is the cancelimage.php script where it uses the $GET method to get the file name from the 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();
  

?>  

try to make the php loop which reads and writes for certain GET var is set, ex. isset($_GET["cancelthis"]); although not the best practise you could use ajax upload plugins for better control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM