gpt4 book ai didi

php - 删除 iframe 会阻止文件上传吗?

转载 作者:行者123 更新时间:2023-12-02 19:40:23 24 4
gpt4 key购买 nike

我一直在试图弄清楚当用户单击“取消”按钮时如何取消文件上传到服务器。实现此目的的最常见方法似乎是在用户单击“取消”按钮时删除 iframe。

我只是想知道这是否是当用户单击“取消”按钮时尝试停止将文件上传到服务器的好方法?如果用户确实点击了“取消”按钮,那么我仍然希望用户能够稍后上传另一个文件(如果他们愿意),所以我希望删除 iframe 时它不会是永久性的。

如果这是最好的方法,那么有人知道如何在单击“取消”按钮时删除 iframe 吗?

下面是开始上传和存储取消按钮功能的代码。

function startImageUpload(imageuploadform){

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


$(".imageCancel").click(function() {
$('.upload_target').get(0).contentwindow
return stopImageUpload();
});

return true;
}

以下是文件停止上传时的代码:

function stopImageUpload(success, imagefilename){

$(sourceImageForm).find('.imagef1_upload_process').css('visibility','hidden');
$(sourceImageForm).find('.imagef1_cancel').css('visibility','hidden');
$(sourceImageForm).find('.imagef1_upload_form').html(result + '<label>Image File: <input name="fileImage" class="fileImage" type="file"/></label><br/><br/><label><input type="submit" name="submitImageBtn" class="sbtnimage" value="Upload" /></label><label>');
$(sourceImageForm).find('.imagef1_upload_form').css('visibility','visible');


return true;
}

表单代码如下:

     var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return startImageUpload(this);' class='imageuploadform' >" + 
//Above is form tag
"<p class='imagef1_upload_process' align='center'>Loading...<br/><img src='Images/loader.gif' /><br/></p><p class='imagef1_upload_form' align='center'><br/><label>" +
//Above is where it displays loading bar while file is uploading
"Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" +
//Above is File Input
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" +
//Above is Upload Button
"</p><p class='imagef1_cancel' align='center'><label>" +
"<input type='button' name='imageCancel' class='imageCancel' value='Cancel' /></label>" +
//Above is Cancel Button
"<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>");
//Above is the iframe which does the transporting

最佳答案

如果你有一个按钮

HTML

<button id="cancel">Cancel</button>

和 JavaScript

$("#cancel").click(function() {
$("iframe[name='upload_target']").attr("src", "javascript:'<html></html>'");
$("iframe[name='upload_target']").remove(); // not needed I think, but anyway it is good to keep the DOM clean
});

并且用户单击该按钮,iframe 的 src 属性将重置为不会创建混合内容警告的变体

关于php - 删除 iframe 会阻止文件上传吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10456917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com