Home > Backend Development > PHP Tutorial > 上传文件后怎么使页面不跳转

上传文件后怎么使页面不跳转

WBOY
Release: 2016-06-13 13:40:14
Original
1653 people have browsed it

上传文件后如何使页面不跳转
代码如下:

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<input type="file" name="file" id="file"> 
<input type="submit" name="submit" value="上传" id="up">

Copy after login

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"]  0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
      $picture=$_FILES["file"]["name"];
    }
  }
else
  {
  echo "请选择合法格式(gif,jpeg和png)且大小不超过2MB的文件!";
  }

Copy after login

点击“上传”后就执行以上Php语句,但是会发生页面跳转。怎样让页面不跳转呢?或者是用别的语言能不能实现相同功能?

------解决方案--------------------
提交时一定会产生跳转的,你可以用提交到插入式框架、弹出式窗口来掩盖这个现象
------解决方案--------------------
去搜一下swfupload、mooUpload等
------解决方案--------------------
通过插件异步上传文件.eg:uploadify、swfupload等
------解决方案--------------------
你是不是要实现在同一页面内上传,
如果是在同一页面内上传,可以这样
upload.php
PHP code

Copy after login
input type="file" name="file" id="file"/>
0) { echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { $picture=$_FILES["file"]["name"]; } } else { echo "请选择合法格式(gif,jpeg和png)且大小不超过2MB的文件!"; } }
------解决方案--------------------
给 form 加个target="" 属性,再加个隐藏的iframe标签,就跳到这里来。
处理后parent.fun()调父窗口响应结果就ok了。
------解决方案--------------------
将form中action设为xxx.php,html和php也放入xxx.php中,那提交文件的时候就是转至当前页面xxx.php进行处理。如果有其他数据,那么可以存入临时数据$tmp=$_POST,然后在显示出来。虽然有点麻烦,却实现了假跳转。
------解决方案--------------------
用插件吧,搜一下ajaxfileupload.js
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template