dongyingla8668 2012-04-16 15:56
浏览 13

如何列出成功上传的文件名?

I have a a form which contains a file input and upload button

<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>

Now what I want is that if an image has finished uploading, at the bottom of this form (in the span tag 'list') I want the name(s) of the file that have been uploaded. So when a file is successfully uploaded, then it should display the name of the uploaded file. If a second file is successfully upoaded, then it displays the name of the uploaded second file below the name of the first file. Is this possible in Javascript?

I have uploading of files all sorted out in php and javascript. Below is javascript function after uploading is complete:

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;
}​

This function is in the same page in the fomr but not in the same page as the uploading script but in the uploading script does call on this function using this javascript code below:

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

Below is part of the uploading php code where it uploads the file into the server:

move_uploaded_file($_FILES["fileImage"]["tmp_name"],"ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
  • 写回答

1条回答 默认 最新

  • dpca31461 2012-04-16 16:07
    关注

    Your PHP callback should contain the name of the file currently uploaded, or even an array of all uploaded files.

    Then, in the stopImageUpload function, read that second parameter and manipulate #list accordinly (update/add 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;
    }​
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)