php上传基础问题求解。问题为红字部分
时间:2011-12-03
来源:互联网
<body>
<?php
$up_types=array('image/jpg',
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'image/x-png');
$max_file_size=2000000;
$destination_folder="uploadimg/";
$imgpreview=1;
$imgpreviewsize=1/2;
?>
<form enctype="multipart/form-data" method="post" name="upload">
<input type="file" name="upfile" />
<input type="submit" value="chuan" />
</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"], $up_types))
{
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;
} 请问把这里注释掉以后是否还是上传成功?还有如果我不移动的话他会传到我的哪个文件夹呐????求解释*/
$pinfo=pathinfo($destination);
$fname=$pinfo["basename"];
echo " <font color=red>已经成功上传</font><br>文件名: <font color=blue>".$destination_folder.$fname."</font><br>";
echo " 宽度:".$image_size[0];
echo " 长度:".$image_size[1];
echo "<br> 大小:".$file["size"]." bytes";
if($imgpreview==1)
{
echo "<br>图片预览:<br>";
echo "<img src=\"".$destination."\" width=".($image_size[0]*$imgpreviewsize)." height=".($image_size[1]*$imgpreviewsize);
echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\">";
}
}
?>
</body>
</html>
<?php
$up_types=array('image/jpg',
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'image/x-png');
$max_file_size=2000000;
$destination_folder="uploadimg/";
$imgpreview=1;
$imgpreviewsize=1/2;
?>
<form enctype="multipart/form-data" method="post" name="upload">
<input type="file" name="upfile" />
<input type="submit" value="chuan" />
</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"], $up_types))
{
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;
} 请问把这里注释掉以后是否还是上传成功?还有如果我不移动的话他会传到我的哪个文件夹呐????求解释*/
$pinfo=pathinfo($destination);
$fname=$pinfo["basename"];
echo " <font color=red>已经成功上传</font><br>文件名: <font color=blue>".$destination_folder.$fname."</font><br>";
echo " 宽度:".$image_size[0];
echo " 长度:".$image_size[1];
echo "<br> 大小:".$file["size"]." bytes";
if($imgpreview==1)
{
echo "<br>图片预览:<br>";
echo "<img src=\"".$destination."\" width=".($image_size[0]*$imgpreviewsize)." height=".($image_size[1]*$imgpreviewsize);
echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\">";
}
}
?>
</body>
</html>
作者: qq56328974 发布时间: 2011-12-03
上传的文件都先存储在临时文件夹,见php.ini upload_tmp_dir
作者: dream1206 发布时间: 2011-12-03
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28