php下传图片

WBOY
发布: 2016-06-13 13:05:19
原创
725 人浏览过

php上传图片

<?php
$uptypes = array (
	'image/jpg',
	'image/jpeg',
	'image/png',
	'image/pjpeg',
	'image/gif',
	'image/bmp',
	'image/x-png'
);
$max_file_size = 2000000; //上传文件大小限制, 单位BYTE
$destination_folder = "image/"; //上传文件路径
$imgpreview = 1; //是否生成预览图(1为生成,其他为不生成);
$imgpreviewsize = 1 / 2; //缩略图比例

if ($_SERVER['REQUEST_METHOD'] == 'POST') //判断是否提交且是要以POST方式提交
	{
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
	if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
		//是否存在文件
		{
		echo "<script> alert('图片不存在!');</script>";
		echo "<script> window.location='SplashAdd.php';</script>";
		exit;
	}
	$file = $_FILES["upfile"];
	if ($max_file_size < $file["size"])
		//检查文件大小
		{
		echo "<script> alert('文件太大!');</script>";
		echo "<script> window.location='SplashAdd.php';</script>";
		exit;
	}
	if (!in_array($file["type"], $uptypes))
		//检查文件类型
		{
		$message = "文件类型不符!".$file["type"];
		echo "<script> alert('$message');</script>";
		echo "<script> window.location='SplashAdd.php';</script>";
		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 "<script> alert('同名文件已经存在了');</script>";
		echo "<script> window.location='SplashAdd.php';</script>";
		exit;
	}
	if (!move_uploaded_file($filename, $destination)) {
		echo "<script> alert('移动文件出错');</script>";
		echo "<script> window.location='SplashAdd.php';</script>";
		exit;
	}
	$pinfo = pathinfo($destination);
	$fname = $pinfo[basename];
}
?>
登录后复制

?

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板