php上传图片
<?php
function uploadFile1($fileInfo)
{
if (!is_null($fileInfo)) {
if ($fileInfo['size'] > 1000000) {
return "上传文件大于1M";
}
$allowExt = array('jpeg', "jpg", "png", "gif");
$ext = strtolower(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
if (!in_array($ext, $allowExt)) {
return "不允许的扩展名";
}
$allowMime = array("image/jpeg", "image/jpg", "image/png", "image/gif");
if (!in_array($fileInfo['type'], $allowMime)) {
return "上传文件类型错误";
}
if (!@getimagesize($fileInfo['tmp_name'])) {
return "不是真实图片";
}
$uploadPath = "attachment/shopimg" . date("Ymd", time());
if (!file_exists($uploadPath)) {
@mkdir($uploadPath);
}
$uniName = md5(uniqid(microtime(true), true));
$destination = $uploadPath . "/" . $uniName . "." . $ext;
if (@move_uploaded_file($fileInfo['tmp_name'], $destination)) {
return "上传成功";
} else {
return "上传失败";
}
} else {
return "文件上传出错";
}
}