做了一个上传图片的小页面。在页面中设定图片最大尺寸不能超过2M,否则做出提示。但是现在的问题是,如果不超过2M的,的确能够正常上传,但是超过2M的,程序就不运行。下面是我写的程序,当文件超过2M的时候,直接echo出没有上传任何图片!,也就是说,程序之运行到if($Submit and $Submit=='Add')这里,接下去直接就判断为$file1==""请大家帮忙解答<?php
if($Submit and $Submit=='Add'){
if($file1!=""){
if($file1_type=="image/jpeg"){
if($file1_size < 2100000){
echo $file1_size;
$path1 = "d:\\htdocs\\painting\\uploaded\\";
$pathbk = "../painting/uploaded/";
$pic1=time().".jpg";
$pic=$path1.$pic1;
$picbk=$pathbk.$pic1;
@copy ($file1,$pic);
$pdate=date("Y-m-d H:i:s");
$size1=GetImageSize($file1);
if($size1[0]>$size1[1]) $goutu="h";
if($size1[0]=$size1[1]) $goutu="s";
if($size1[0]<$size1[1]) $goutu="w";
$sql="insert into picture (name,category,caption,pic,pdate,sizeh,sizew,goutu,picbk) values ('','','','$pic','$pdate','','','$goutu','$picbk')";
$q->query($DB,$sql);
$ssql="select max(id) as maxid from picture";
$q->query($DB,$ssql);
$rhw=$q->getrow();
$id=$rhw[maxid];
echo "<p>".$id."<p>";
}
else{
echo "图片尺寸超过2M,请缩小图片后再次上传";
exit;
}
}
else{
echo "只能上传JPG格式的图片";
exit;
}
}
else{
echo "没有上传任何图片!";
exit;
}
}if($submit and $submit=='Revise'){}?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="/webimg/head.css" type=text/css rel=stylesheet>
<title>无标题文档</title>
</head><body bgcolor=ECECFF>
<script language="JavaScript">
function checkform()
{ if(document.uploadedit1.pdate.value=="")
{
alert("You must input upload time!");
document.uploadedit1.pdate.focus();
return false;
}
if(document.uploadedit1.name.value=="")
{
alert("You must input name time!");
document.uploadedit1.name.focus();
return false;
}
if(document.uploadedit1.caption.value=="")
{
alert("You must input caption time!");
document.uploadedit1.caption.focus();
return false;
}
if(document.uploadedit1.sizeh.value=="")
{
alert("You must input sizeh!");
document.uploadedit1.sizeh.focus();
return false;
}
if(document.uploadedit1.sizew.value=="")
{
alert("You must input sizew!");
document.uploadedit1.sizew.focus();
return false;
}
if(document.uploadedit1.category.options[document.uploadedit1.category.selectedIndex].value=="")
{
alert("You must select the category!");
document.uploadedit1.category.focus();
return false;
}
}
</script>
<?
if(!isset($id)){
echo "进入路径出现错误,请返回重新提交图片。";
echo "</body></html>";
exit;
}
else{
$sQl="select * from picture where id=$id";
$q->query($DB,$sQl);
$row=$q->getrow();
?>
<table width="500" border="1" cellspacing="0" cellpadding="0">
<form name=uploadedit1.shtm method=post action=uploadedit1.shtm?id=<? echo $id;?> onSubmit="return checkform()">
<tr>
<td colspan="2" align=center><img src=<? echo $picbk;?> width=450></td>
</tr>
<tr>
<td width="201">提交时间</td>
<td width="293"><input type="text" name="pdate" value="<? echo $row[pdate];?>"></td>
</tr>
<tr>
<td width="201">作品名</td>
<td width="293"><input type="text" name="name" value="<? echo $row[name];?>"></td>
</tr>
<tr>
<td>作品分类</td>
<td>
<select name="category">
<option value=>请选择所属类别</option>
<?
$ssqql="select id,name from category order by id desc";
$q->query($DB,$ssqql);
while($rew=$q->getrow()){
echo "<option value=".$rew[id]." ";
if($row[category]=$rew[id]) echo "selected";
echo ">".$rew[name]."</option>";
}
?>
</select></td>
</tr>
<tr>
<td>作品描述</td>
<td><textarea name="caption"><?echo $row[caption];?></textarea></td>
</tr>
<tr>
<td>作品尺寸</td>
<td>长
<input name="sizeh" type="text" size="10" value="<? echo $row[sizeh];?>">
宽
<input name="sizew" type="text" size="10" value="<? echo $row[sizew];?>">
(单位:厘米) </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</form>
</table>
</body>
</html>
<?
}
?>
if($Submit and $Submit=='Add'){
if($file1!=""){
if($file1_type=="image/jpeg"){
if($file1_size < 2100000){
echo $file1_size;
$path1 = "d:\\htdocs\\painting\\uploaded\\";
$pathbk = "../painting/uploaded/";
$pic1=time().".jpg";
$pic=$path1.$pic1;
$picbk=$pathbk.$pic1;
@copy ($file1,$pic);
$pdate=date("Y-m-d H:i:s");
$size1=GetImageSize($file1);
if($size1[0]>$size1[1]) $goutu="h";
if($size1[0]=$size1[1]) $goutu="s";
if($size1[0]<$size1[1]) $goutu="w";
$sql="insert into picture (name,category,caption,pic,pdate,sizeh,sizew,goutu,picbk) values ('','','','$pic','$pdate','','','$goutu','$picbk')";
$q->query($DB,$sql);
$ssql="select max(id) as maxid from picture";
$q->query($DB,$ssql);
$rhw=$q->getrow();
$id=$rhw[maxid];
echo "<p>".$id."<p>";
}
else{
echo "图片尺寸超过2M,请缩小图片后再次上传";
exit;
}
}
else{
echo "只能上传JPG格式的图片";
exit;
}
}
else{
echo "没有上传任何图片!";
exit;
}
}if($submit and $submit=='Revise'){}?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="/webimg/head.css" type=text/css rel=stylesheet>
<title>无标题文档</title>
</head><body bgcolor=ECECFF>
<script language="JavaScript">
function checkform()
{ if(document.uploadedit1.pdate.value=="")
{
alert("You must input upload time!");
document.uploadedit1.pdate.focus();
return false;
}
if(document.uploadedit1.name.value=="")
{
alert("You must input name time!");
document.uploadedit1.name.focus();
return false;
}
if(document.uploadedit1.caption.value=="")
{
alert("You must input caption time!");
document.uploadedit1.caption.focus();
return false;
}
if(document.uploadedit1.sizeh.value=="")
{
alert("You must input sizeh!");
document.uploadedit1.sizeh.focus();
return false;
}
if(document.uploadedit1.sizew.value=="")
{
alert("You must input sizew!");
document.uploadedit1.sizew.focus();
return false;
}
if(document.uploadedit1.category.options[document.uploadedit1.category.selectedIndex].value=="")
{
alert("You must select the category!");
document.uploadedit1.category.focus();
return false;
}
}
</script>
<?
if(!isset($id)){
echo "进入路径出现错误,请返回重新提交图片。";
echo "</body></html>";
exit;
}
else{
$sQl="select * from picture where id=$id";
$q->query($DB,$sQl);
$row=$q->getrow();
?>
<table width="500" border="1" cellspacing="0" cellpadding="0">
<form name=uploadedit1.shtm method=post action=uploadedit1.shtm?id=<? echo $id;?> onSubmit="return checkform()">
<tr>
<td colspan="2" align=center><img src=<? echo $picbk;?> width=450></td>
</tr>
<tr>
<td width="201">提交时间</td>
<td width="293"><input type="text" name="pdate" value="<? echo $row[pdate];?>"></td>
</tr>
<tr>
<td width="201">作品名</td>
<td width="293"><input type="text" name="name" value="<? echo $row[name];?>"></td>
</tr>
<tr>
<td>作品分类</td>
<td>
<select name="category">
<option value=>请选择所属类别</option>
<?
$ssqql="select id,name from category order by id desc";
$q->query($DB,$ssqql);
while($rew=$q->getrow()){
echo "<option value=".$rew[id]." ";
if($row[category]=$rew[id]) echo "selected";
echo ">".$rew[name]."</option>";
}
?>
</select></td>
</tr>
<tr>
<td>作品描述</td>
<td><textarea name="caption"><?echo $row[caption];?></textarea></td>
</tr>
<tr>
<td>作品尺寸</td>
<td>长
<input name="sizeh" type="text" size="10" value="<? echo $row[sizeh];?>">
宽
<input name="sizew" type="text" size="10" value="<? echo $row[sizew];?>">
(单位:厘米) </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</form>
</table>
</body>
</html>
<?
}
?>
解决方案 »
- 求高手解决:HTML更新时候,出现“DedeTag Engine Create File False”的问题,怎么解决?
- 求职接单zencart模板制作,zencart模板安装,zencart模板修改,zencart模板开发
- template
- 请高手讲解一下PHP Web services 技术
- 怎么样才能定时按指定的关键字对论坛进行搜索,如phpwind
- 类似QQ空间的评论表是怎么设计的。
- PHP如何比较变量的大小
- 为什么jqgrid用php显示不了数据
- php新手,新建了个项目,运行报错
- 如何像phpmyadmin一样双击编辑离开提交
- 招Actionscript工程师
- windows 下创建 apache+mysql+php环境后,运行上传文件程序出现的问题
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="/webimg/head.css" type=text/css rel=stylesheet>
<title></title><body bgcolor=ECECFF>
<script language="JavaScript">
function checkdata()
{ if(document.uploadpic.file1.value=="")
{
alert("请选择要上传的图片!");
document.uploadpic.file1.focus();
return false;
}
}
</script>
<form action="uploadedit1.shtm" method="post" enctype="multipart/form-data" name="uploadpic" onSubmit="return checkdata()">
<br>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>选择要上传的图片</td>
<td><input type="file" name="file1"></td>
</tr>
<tr>
<td>点击提交(图片尺寸不要超过2M)</td>
<td><input type="submit" name="Submit" value="Add"></td>
</tr>
</table>
</form>
</BODY>
</HTML>另外,我刚才试着在if($Submit and $Submit=='Add'){ 的后面加入 echo $file1 发现没有打印出来。
并且,在echo "没有上传任何图片!"; 这个后面也没有打印出来
upload_max_filesize = 2M
你看一下有没有改过