메뉴 건너뛰기

프로그램언어

조회 수 1135 추천 수 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
번호 제목 날짜 조회 수
340 리다이렉션(페이지 이동)의 3가지 방법, location.href 2017.03.07 40132
339 [PHP] 게시판 글쓰기와 이미지 파일 DB 저장 및 불러오기 예제 2017.02.19 35886
338 $_SERVER 환경변수 2016.09.21 33237
337 PHP에서 PDF파일 생성하기 2014.02.27 32777
336 PHP에서 자바스크립트 값 가져오기 2014.02.27 31635
335 Class를 이용한 DB Connection 소스 (Oracle, MyS 2014.02.27 30503
334 htmlentities <-> html_entity_decode (엔티티 2014.04.12 30396
333 무조건 알아야 할 PHP 속도 테스트 14 가지 2014.02.27 30280
332 PHP로 Excel 파일 만들기... 2014.02.27 30257
331 Text를 GD 이미지로 뿌리기 2014.02.27 29813
330 php 엑셀 다운로드 구현 2017.03.07 29786
329 글내용 이미지 리사이징 2014.02.27 29446
328 쿠키변수받기 2014.02.27 29211
327 Record Drag/Drop Position 2014.02.27 29201
326 간단한 PHP 파일 업로드, 다운로드 구현 2017.03.06 28547
325 DB상의 많은 파일을 한꺼번에 다운받기 2014.02.27 28332
324 GD를 이용한 스팸성 게시물 차단을 위한 보안 단어 입력 예제 2014.02.27 26945
323 주간날짜 뽑아오기 2014.02.27 26731
322 전화번호에 하이픈(-) 넣기 2015.04.14 26622
321 PHP 변수전달 GET, POST 2015.04.14 26565
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved