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 "文件上傳出錯";
}
}