我有一个包含文件输入和上传按钮的表单
<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>
现在我想要的是,如果图像已经完成上传,则在此表单的底部(在span标签'list'中)我想要已经上传的文件的名称。因此,当文件成功上传时,它应显示上传文件的名称。如果第二个文件成功上载,则它会在第一个文件的名称下方显示上载的第二个文件的名称。 这可能在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;
答案 0 :(得分:0)
您的PHP回调应该包含当前上传文件的名称,甚至包含所有上传文件的数组。
然后,在stopImageUpload
函数中,读取第二个参数并按照{更新/添加html}操作#list
:
<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;
}