PHP获取JS弹出页面(上传框)的值不成功
主页面a.php,点击其中按钮后调取up.php页面,上传图片后自动关闭,并将路径信息返回给a.php上的输入框。单独调测up.php正常,能够上传文件并自动关闭。但是被...
主页面a.php,点击其中按钮后调取up.php页面,上传图片后自动关闭,并将路径信息返回给a.php上的输入框。单独调测up.php正常,能够上传文件并自动关闭。但是被a.php调取后,只能获取路径信息、自动关闭。但不能正确上传文件,请给与帮助,谢谢!
up.php代码如下:
<?php
$uptypes=array('image/jpg', 'image/jpeg');
$max_file_size=2000000;
$destination_folder="uploadimg/";
?>
<html>
<base target="_self">
<head>
<title>上传</title>
<script type="text/javascript" language="javascript">
function dd(strid, strvalue) {
var str = new Array(strid, strvalue);
window.returnValue = str;
window.close();
}
</script>
</head>
<form enctype="multipart/form-data" method="post" name="upform">
上传文件 <input name="upfile" id="upfile" type="file">
<input type="submit" value="上传" onclick="javascript:dd( '1', document.getElementById('upfile').value);"/><br/>
允许*.jpg *.jpeg *.gif *.png
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{ if (!is_uploaded_file($_FILES['upfile']['tmp_name']))
{echo "图片不存在!"; exit; }
$file = $_FILES['upfile'];
if($max_file_size < $file['size']) { echo "文件太大!"; exit; }
if(!in_array($file["type"], $uptypes))
{ echo "文件类型不符!".$file['type']; exit; }
if(!file_exists($destination_folder))
{mkdir($destination_folder); }
$filename=$file['tmp_name'];
$image_size = getimagesize($filename);
$pinfo=pathinfo($file["name"]);
$ftype=$pinfo['extension'];
$destination = $destination_folder.time().".".$ftype;
if (file_exists($destination) && $overwrite != true)
{echo "同名文件已经存在了"; exit; }
if(!move_uploaded_file ($filename, $destination))
{ echo "移动文件出错"; exit; }}
?>
a.php如下:<html> <script type="text/javascript">
function gg(openwindow, aa, bb) {
var
str = window.showModalDialog(openwindow, window,
"dialogWidth=500px;dialogHeight=70px;center=yes;help=no;resizable=no;status=no");
if (!str)
return;
document.getElementById(aa).value = str[0];
document.getElementById(bb).value = str[1];
}
</script><form >
<div><input id="txt"/>
<input type="button" id="sel" onclick="javascript:gg('up.php','hf','txt')" value="上传" />
<input type="hidden" id="hf"/>
</div>
</form></html> 展开
up.php代码如下:
<?php
$uptypes=array('image/jpg', 'image/jpeg');
$max_file_size=2000000;
$destination_folder="uploadimg/";
?>
<html>
<base target="_self">
<head>
<title>上传</title>
<script type="text/javascript" language="javascript">
function dd(strid, strvalue) {
var str = new Array(strid, strvalue);
window.returnValue = str;
window.close();
}
</script>
</head>
<form enctype="multipart/form-data" method="post" name="upform">
上传文件 <input name="upfile" id="upfile" type="file">
<input type="submit" value="上传" onclick="javascript:dd( '1', document.getElementById('upfile').value);"/><br/>
允许*.jpg *.jpeg *.gif *.png
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{ if (!is_uploaded_file($_FILES['upfile']['tmp_name']))
{echo "图片不存在!"; exit; }
$file = $_FILES['upfile'];
if($max_file_size < $file['size']) { echo "文件太大!"; exit; }
if(!in_array($file["type"], $uptypes))
{ echo "文件类型不符!".$file['type']; exit; }
if(!file_exists($destination_folder))
{mkdir($destination_folder); }
$filename=$file['tmp_name'];
$image_size = getimagesize($filename);
$pinfo=pathinfo($file["name"]);
$ftype=$pinfo['extension'];
$destination = $destination_folder.time().".".$ftype;
if (file_exists($destination) && $overwrite != true)
{echo "同名文件已经存在了"; exit; }
if(!move_uploaded_file ($filename, $destination))
{ echo "移动文件出错"; exit; }}
?>
a.php如下:<html> <script type="text/javascript">
function gg(openwindow, aa, bb) {
var
str = window.showModalDialog(openwindow, window,
"dialogWidth=500px;dialogHeight=70px;center=yes;help=no;resizable=no;status=no");
if (!str)
return;
document.getElementById(aa).value = str[0];
document.getElementById(bb).value = str[1];
}
</script><form >
<div><input id="txt"/>
<input type="button" id="sel" onclick="javascript:gg('up.php','hf','txt')" value="上传" />
<input type="hidden" id="hf"/>
</div>
</form></html> 展开
1个回答
展开全部
代码是没问题的,你说的上传不成功,我猜可能是你的图片类型不对,或者你扩大一下你的上传类型:image/pjpeg,image/gif....等等
追问
$uptypes=array(
'image/jpg',
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'image/x-png'
); 因提问问题字数限制,没写全部代码,我上面说了,up.php单独调测上传没问题的,就是被a.php调用后,上传出现问题。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询