namespace vendor; class upload_file{ static function images($inputName, $targetDir, $maxSize = 5000000) { if (!isset($_FILES[$inputName]) || $_FILES[$inputName]['error'] == UPLOAD_ERR_NO_FILE) { return "没有文件上传"; } $fileTmpPath = $_FILES[$inputName]['tmp_name']; $fileName = $_FILES[$inputName]['name']; $fileSize = $_FILES[$inputName]['size']; $fileError = $_FILES[$inputName]['error']; if ($fileError === UPLOAD_ERR_OK) { if ($fileSize > $maxSize) { return "文件过大"; } if (is_uploaded_file($fileTmpPath)) { $targetPath = "upload".DIRECTORY_SEPARATOR.$targetDir . DIRECTORY_SEPARATOR ; upload_file::mkdirs($targetPath); $targetPath=$targetPath. date("YmdHis").md5(rand(0,999999)).".jpg"; if (move_uploaded_file($fileTmpPath, $targetPath)) { return $targetPath; } else { return ""; } } } else { return ""; } } static function mkdirs($a1, $mode = 0777) { if (is_dir($a1) || @mkdir($al, $mode)) return TRUE; if (!upload_file::mkdirs(dirname($a1), $mode)) return FALSE; return @mkdir($a1, $mode); } }