Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
themeEmacs
linenumberstrue
<?php
    //업로드 디렉토리
    $uploadDir = 'uploads/images';

    //폼 데이터 이름
    $fieldName = 'file';

    //파일 이름
    $fileName = explode('.', $_FILES[$fieldName]['name']);

    //파일 확장자// v2.3.0 부터 파일명이 document.word.pb에서 document.pb로 변경됨
    $extension = end($fileName);

    //임시 파일 이름
    $tmpName = $_FILES[$fieldName]['tmp_name'];

    //저장될 새로운 파일이름
    $newFileName = sha1(microtime());

    //실제 파일 업로드 경로
    $fileUploadPath = "${uploadDir}/${newFileName}.${extension}";

    //파일을 저장합니다
    move_uploaded_file($tmpName, $fileUploadPath);


	// JSON Encoder를 include 한다.
	include("./JSON.phps");

    //클라이언트로 응답을 보냅니다.
    header('Content-Type: application/json');
    echo json_encode_new(array(
        'uploadPath' => $fileUploadPath,
    ));


	function json_encode_new($data) {
		$json = new Services_JSON();
		return($json->encode($data));
	}
?>

...