简体   繁体   English

如何显示正确的消息?

[英]how to display the correct message?

I have a php script below known as cancelimage.php where it will display a cancel message: 我下面有一个PHP脚本,称为cancelimage.php,它将显示一条取消消息:

<?php

$image_file_name = $_FILES['fileImage']['name'] ;

    echo "$image_file_name Upload was Canceled";


?>

The problem is that when I click on the "Cancel" button, it does not display this message. 问题是,当我单击“取消”按钮时,它不显示此消息。 Instead it displays the message "There was a error during file upload". 而是显示消息“文件上传期间发生错误”。 I believe the reason this message is coming up instead is because I am stating "return stopImageUpload". 我相信出现此消息的原因是因为我声明“ return stopImageUpload”。

So what my question is that how can I return to stopImageUpload like I am doing now, but instead be able to display the cancel message instead of the message it is displaying now? 所以我的问题是,如何才能像现在一样返回stopImageUpload,但是能够显示取消消息而不是现在显示的消息?

Below is my current attempt on trying to fix this but which has failed. 以下是我当前尝试解决此问题的尝试,但失败了。 Below shows both the cancel button function and the stopImageUpload function: 下面显示了取消按钮功能和stopImageUpload功能:

var cancelimagecounter = 0;
function startImageUpload(imageuploadform, imagefilename) {
    cancelimagecounter++;
    var _cancelimagecounter = cancelimagecounter;
    $('.imageCancel').on("click", function (event) {
        $('.upload_target').get(0).contentwindow
        $("iframe[name='upload_target']").attr("src", "javascript:'<html></html>'");
        jQuery.ajax("cancelimage.php?fileImage=" + image_file_name).done(function (data) {
            $(".imageemsg" + _cancelimagecounter).html(data);
        });
        return stopImageUpload();
    });
    return true;
}
var imagecounter = 0;
function stopImageUpload(success, imagefilename) {
    var result = '';
    if (success == 1) {
        result = '<span class="imagemsg' + imagecounter + '">The file was uploaded successfully!</span><br/><br/>';
        $('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" image_file_name="' + imagefilename + '">Remove</button><br/><hr/></div>');
    } else {
        result = '<span class="imageemsg">There was an error during file upload!</span><br/><br/>';
    }
    return true;
}

Preface: Ajax is not my strong suit..... 前言:Ajax不是我的强项。

You are relying on php to pull the file name... but PHP can't get the file name until the upload is initiated. 您依靠php来提取文件名...但是PHP在启动上传之前无法获取文件名。 You need to pull the file name from the DOM (the input button) if you want to display the file name without an actual upload taking place. 如果要显示文件名而不进行实际的上载,则需要从DOM(输入按钮)中提取文件名。

$('input:file').change(function(){
    if ($(this).val()) {
    var filename = $(this).val().replace('C:\\fakepath\\', '');
    }
    $('.imageemsg').html('<p>this is the filename' + filename + '</p>');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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