0

我有一个包含文件输入和上传按钮的表单

<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='stopImageUpload(this);' class='imageuploadform' >
    <p class='imagef1_upload_form' align='center'><label>Image File: <input name='fileImage' type='file' class='fileImage' /></label>
        <input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>
    </p>
    <p><span class='list></span></p>
</form>

现在我想要的是,如果图像已完成上传,则在此表单的底部(在跨度标记“列表”中)我想要已上传文件的名称。因此,当文件成功上传后,它应该显示上传文件的名称。如果第二个文件成功上传,则它会在第一个文件的名称下方显示上传的第二个文件的名称。这在Javascript中可能吗?

我已经上传了所有用 php 和 javascript 整理的文件。下面是上传完成后的javascript函数:

function stopImageUpload(success) {
    var result = '';
    if (success == 1) {
        result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
    }
    else {
        result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
    };
    return true;
}​

此函数在 fomr 中的同一页面中,但与上传脚本不在同一页面中,但在上传脚本中确实使用以下 javascript 代码调用此函数:

<script language="javascript" type="text/javascript">window.top.window.stopImageUpload(<?php echo $result; ?>);</script> 

以下是将文件上传到服务器的部分上传 php 代码:

move_uploaded_file($_FILES["fileImage"]["tmp_name"],"ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
4

1 回答 1

0

您的 PHP 回调应该包含当前上传的文件的名称,甚至是所有上传文件的数组。

然后,在stopImageUpload函数中,读取第二个参数并#list相应地操作(更新/添加 html):

<ul id="list"></ul>
function stopImageUpload(success, filename) {
    var result;
    if (success == 1)
        result = '<li class="msg">The file '+filename+' was uploaded successfully!</li>';
    else
        result = '<li class="emsg">There was an error during upload of file '+filename+'!</li>';
    $('#list').append(result);
    return true;
}​
于 2012-04-16T16:07:22.980 回答