首先,并不是欺骗大家,只是提出一个思路,在xampp下的firefox,chrome,ie都试过,理论上应该是可以的,不过,firefox只成功一次,其余都取到空值,chrome没成功过,ie常常取到旧的。是这样做的,利用cookie,当文件比较小的时候,且是文本文档,可以做一个form,无刷新POST,不用submit提交,而用button,设onclick。具体如下:
html:
<form enctype="multipart/form-data" action="upload.php" method="POST" id=m2up target="ifam">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<input name="userfile" type="file">
<input type="button" value="显示" onclick="document.getElementById('m2up').submit();getFile();" >
</form>
<iframe id='ifm' name='ifm' style="display:none" >你好</iframe>然后在服务端把这个文件的内容写入cookie,在getFile()里读出来,并写入到文本区域。想问问高手们,这种思路是否可行?是否有价值?另一种方式我想的更多,在php服务端用echo,这样本来是显示在刷新窗口的内容能否通过定向到隐藏的iframe中,然后再从ifm取出来?就
是从那个隐藏的iframe里头取这个值,行不行?我找了半天没找到方法。
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<input name="userfile" type="file">
<input type="button" value="显示" onclick="document.getElementById('m2up').submit();getFile();" >
</form>
<iframe id='ifm' name='ifm' style="display:none" >你好</iframe>