메뉴 건너뛰기

프로그램언어

조회 수 1129 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
<form method="post" name="form1">
<input type="hidden" name="ucc_url">
제목 : <input style="WIDTH: 500px" maxlength="100" name="title">
영상첨부 : <div onclick="youtube_open();" class="btn_100">동영상 첨부</div>
</form>
<div><input onclick="check_in();" type="button" value="글저장"></div>
<form method="post" name="form2">
<input type="hidden" name="title">
</form>
<script language="javascript">
    function youtube_open(){
        if(document.form1.title.value==''){
            alert('제목을 먼저 입력해주세요.\n유튜브 영상에 표시될 제목입니다.');
            document.form1.title.focus();
            return;
        }
        f = document.form2;
         window.open('','youtPop','width=400,height=300');
         f.target = 'youtPop';
         f.action = 'youtube_upload.php';
         f.title.value=document.form1.title.value;
         f.submit();
    }
                
               function check_in(){
                  if(document.form1.ucc_url.value==''){
                     alert('영상을 첨부해주세요.');
                     return;
                  }
                  document.form1.action='ok.php';
                  document.form1.submit();
              }
</script>
 

 

youtube_upload.php

<!--?php
$youtube_email = "유튜브 로그인 아이디"; // Change this to your youtube sign in email.
$youtube_password = "유튜브 로그인 패스워드"; // Change this to your youtube sign in password.
  
$postdata = "Email=".$youtube_email."&Passwd=".$youtube_password."&service=youtube&source=Example";
$curl = curl_init("https://www.google.com/youtube/accounts/ClientLogin");
curl_setopt($curl, CURLOPT_HEADER, "Content-Type:application/x-www-form-urlencoded");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
$response = curl_exec($curl);
curl_close($curl);
  
list($auth, $youtubeuser) = explode("\n", $response);
list($authlabel, $authvalue) = array_map("trim", explode("=", $auth));
list($youtubeuserlabel, $youtubeuservalue) = array_map("trim", explode("=", $youtubeuser));
  
 $_REQUEST['title'] = iconv("euc-kr", "utf-8", $_REQUEST['title']);  // 외국 자료 원본소스에서 한글처리 때문에 추가
  
$youtube_video_title = $_REQUEST['title']; // This is the uploading video title.
$youtube_video_description = $_REQUEST['title']; // This is the uploading video description.
$youtube_video_category = "Entertainment"; // This is the uploading video category.   //카테고리는 정책적으로 지정된것중에서만 써야되는듯...
$youtube_video_keywords = $_REQUEST['title']; // This is the uploading video keywords.
  
$data = '<?xml version="1.0"?-->
            <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007">
              <media:group>
                <media:title type="plain">'.$youtube_video_title.'</media:title>
                <!--?xml:namespace prefix = "media" /--><media:description type="plain">'.$youtube_video_description.'</media:description>
                <media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">'.$youtube_video_category.'</media:category>
                <media:keywords>'.$youtube_video_keywords.'</media:keywords>
               
            </media:group></entry>';
  
$key = "발급받은 유튜브 개발자 키"; // Get your key here: http://code.google.com/apis/youtube/dashboard/.
  
$headers = array("Authorization: GoogleLogin auth=".$authvalue,
                 "GData-Version: 2",
                 "X-GData-Key: key=".$key,
                 "Content-length: ".strlen($data),
                 "Content-Type: application/atom+xml; charset=UTF-8");
  
$curl = curl_init("http://gdata.youtube.com/action/GetUploadToken");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_REFERER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
  
$response = simplexml_load_string(curl_exec($curl));
curl_close($curl);
?>
<!--?php
$nexturl = "리턴값을 받을 페이지 풀url..여기서는 일단 http://도메인/upload_ok.php"; // This parameter specifies the URL to which YouTube will redirect the user's browser when the user uploads his video file.
?-->
 
 
 
 
<SCRIPT type=text/javascript>
  function checkForFile() {
    if (document.form_y.file.value!=='') {
        document.form_y.submit();
    }else{
        alert('영상을 첨부해주세요.');
    }
  }
</SCRIPT>
 
 
<form enctype="multipart/form-data" method="post" name="form_y" action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($nexturl)); ?>">
  파일 : <input id="file" type="file" name="file">
  제목 : <!--? echo($youtube_video_title); ?-->
  <input type="hidden" value="<?php echo($response->token); ?>" name="token">
  <input onclick="checkForFile();" type="button" value="유튜브로 전송">
</form>
※ 업로드창이 자동으로 닫힐 때까지 창을 닫지 마세요.
※ 업로드가 완료되면 이 창은 자동으로 닫힙니다.
 

 

 

<!--?
    $ucc_url = $_REQUEST["id"];
    $ucc_status = $_REQUEST["status"];
     
    if($ucc_status == "200"){
?-->
        <SCRIPT language=javascript>
        <!--
            opener.document.form1.ucc_url.value='<?=$ucc_url?>';
            window.close();
        //-->
        </SCRIPT>
<!--?
    }else{
?-->
        <SCRIPT language=javascript>
        <!--
            alert("실패");
            window.close();
        //-->
        </SCRIPT>
<!--?
    }  
?-->

 

썸네일소스

<iframe width="640" height="360" src="https://www.youtube.com/embed/<!--?=$ucc_url?-->" frameborder="0" allowfullscreen></iframe>
<img src="http://i2.ytimg.com/vi/%3C?=$ucc_url?>/default.jpg">

 


List of Articles
번호 제목 날짜 조회 수
280 PHP와 HTML과 자바스크립트의 관계 2021.03.26 310
279 TIFF, GIF 여러장 변환 file 2021.03.26 323
278 정규표현식 2021.03.26 311
277 date() 함수의 출력 형식 2021.03.26 241
276 확장자 추출 하기 2021.03.26 306
275 서브도메인 세션 공유 2021.03.26 537
274 가변변수로 만든 배열 2021.03.26 272
273 HEREDOC <<< ( PHP에서 echo로 HTML쉽게 표시하기 ) 2021.03.26 370
272 배열 연산자 []= 에 대해서 2021.03.26 231
271 Predefined Variables (미리 정의된 변수들) 2021.03.26 274
270 current() next() key() 그외 배열관련 함수 2021.03.26 253
269 비교연산자 ( === 에 관해서 ) 2021.03.25 307
268 큰따옴표(") 와 작은따옴표(') 2021.03.25 270
267 mysql_free_result(); 관련 오류 2021.03.25 288
266 phpMyAdmin WebMysql 에 CSV 엑셀 파일 업로드 입력하기 ( Excel / Upload / data / 데이터 / 데이타 ) file 2021.03.25 725
» PHP + 유튜브(youtube) 동영상 업로드 연동 소스 2021.01.21 1129
264 다중파일 업로드 + 이미지 미리보기 (Javascript, jQuery ) file 2020.12.15 903
263 경로 제외한 파일 이름만 선택하는 방법, Basename() 2020.11.23 429
262 쿠키 확인 후 만료시 세션 파괴하는 방법 2020.11.23 312
261 DAUM 지도 API 좌표→주소(주소->좌표) 변환 2020.10.05 431
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved