日期:2014-05-17 浏览次数:21208 次
<input type="file" name="file" id="file"/> <input type="submit" name="submit" value="上传" id="up"/>
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
$picture=$_FILES["file"]["name"];
}
}
else
{
echo "请选择合法格式(gif,jpeg和png)且大小不超过2MB的文件!";
}
<form name="wc" action="" method="post">
input type="file" name="file" id="file"/>
<input type="submit" name="submit" value="上传" id="up"/>
</form>
<?php
if($_POST['sumbit']){
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
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