<?php
/**
 * DATE 함수의 약간 변형
 */
if (!empty($_FILES) && empty($_FILES["file"]["error"])) {
	if (isset($_FILES)
			&& isset($_FILES['file'])
			&& isset($_FILES['file']['name'])
			&& isset($_FILES['file']['name'][0])) {

		$servername = $_SERVER['HTTP_HOST'];
		$username = "username";
		$password = "password";

		// Create connection
		$conn = mysqli_connect($servername, $username, $password);

		// Check connection
		if (!$conn) {
			die("Connection failed: " . mysqli_connect_error());
		}
		echo "Connected successfully";


		$hostUrl = $_SERVER['HTTP_HOST'];
		$baseDir = $_SERVER['DOCUMENT_ROOT'];
		$pathDir = '/uploads/editor/' . cdate('Y') . '/' . cdate('m') . '/';

		$fileName = $_FILES["file"]["name"];
		$tmpFileName = $_FILES["file"]["tmp_name"];

		$targetFilePath = $baseDir.$pathDir.basename($fileName);
		$imageFileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); // 확장자

	    if(getimagesize($tmpFileName) !== false) {
	        if(move_uploaded_file($tmpFileName, $targetFilePath)){
	        	echo "http://".$hostUrl.$pathDir.$fileName;
	        }else{
				return false;
	        }
	    }
	}
}
