[WEB] PHP에서 FTP 파일 올리기.


input type="file" name="cover"


if($_FILES["cover"]["size"] > 0) {  //파일 확인



---------------------------------------------------------------------------------------------
 $sTargetPath = "저장 위치."

1. 파일업로드  (서버에 저장)
    if(!move_uploaded_file($_FILES["cover"]["tmp_name"], $sTargetPath)) {
        js_alert("파일업로드에 실패하였습니다");
    }
---------------------------------------------------------------------------------------------
$sPath =  "저장위치";

2. FTP를 이용해서 CDN에 업로드

    $conn_id = ftp_connect($gConf["ftp_server"],$gConf["ftp_port"]);

    // login with username and password
    $login_result = ftp_login($conn_id, $gConf["ftp_user"], $gConf["ftp_pass"]);

    // check connection
    if ((!$conn_id) || (!$login_result)) {
            echo "Attempted to connect to ftp_server";
            die;
    } else {
    ftp_pasv($conn_id, true);  // 이거 없으면 업로드 안됨. 검색 보면 없이 하는곳도
    }

    /* ftp_put($conn_id, 원격서버에 업로드될 파일명, 현재 서버의 파일명, 모드) */
    $upload = ftp_put($conn_id, $sPath, $_FILES["cover"]["tmp_name"], FTP_BINARY);

    // check upload status
    if (!$upload) {
        echo "Ftp upload has failed!";
    } else {
        //echo "ok";
    }
     // close the FTP stream
    ftp_quit($conn_id);

}

댓글

이 블로그의 인기 게시물

[문서] excel 체크박스 삭제

[DB] MySQL 백업 / 복원

[WEB] ASP.NET System.NullReferenceException: 개체 참조가 개체의 인스턴스로 설정되지 않았습니다.