It's simple, but for me this is not simple. I use PHP 5.6.
This works:
<form method="post" action="http://RUSRRJIZ3A2WRL.....ML1IU6D9G#host.localhost/api/images/products/88" enctype="multipart/form-data" >
<input type='file' name='image' />
<button type="submit" >send</button>
</form>
But this not:
$id_product = 88;
$cfile = curl_file_create('bigimage.jpg','image/jpeg','bigimage');
$data = array('image' => $cfile);
$header = array('Content-Type: multipart/form-data');
$url = PS_SHOP_PATH . "api/images/products/$id_product";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':');
//curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '#'.realpath('bigimage.jpg').";type=jpeg"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(!$result = curl_exec($ch)) throw new Exception('curl_exec generate an error.');
curl_close($ch);
Can anyone help me? Maybe it can be a security error? Only error 500 is sometimes shown in log.
For me I use :
// envois de la nouvelle image
$url = PS_SHOP_PATH. "/api/images/products/".$product->id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '#'.$image_path . ";type=" . $image_mime));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Thanks for posting your code :
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
Without it my upload fails with ERROR 500.
Thnaks again !
Related
Once I select check boxes & OnClick Insert Button I am calling php function present in api.php page to display results under status column.
But its not fetching any results .
below is api url page results :
table.php - php code
<p><button type= "button" id="show_status" >Show Status</button></p>
<table class="tbl-qa" border="1">
<thead>
<tr>
<th class="table-header">ID</th>
<th class="table-header">ORDERID</th>
<th class="table-header">Status</th>
</tr>
</thead>
<tbody id="table-body">
<?php
if(!empty($orderrecords))
{
foreach($orderrecords as $k=>$v)
{?>
<tr class="table-row" id="table-row-<?php echo $orderrecords[$k]["id"]; ?>" tabindex="<?php echo $tabindex;?>">
<td>
<input type="checkbox" name="assigneeid" class="assigneeid-order" value="<?php echo $orderrecords[$k]["order_id"]; ?>">
</td>
<td><?php echo $orderrecords[$k]["order_id"]; ?></td>
<td id="<?php echo checkecomstatus($orderrecords[$k]["order_id"]);?>"></td>
</tr>
<?php
$tabindex++;
}
}?>
</tbody>
</table>
<input type="hidden" name="ordercheckallIDs" id="ordercheckallIDs" value="<?php echo $ordercheckall;?>"/>
table.php - javascript code
$('#show_status').click(function(){
var selected = [];
$('.assigneeid-order input:checked').each(function() {
selected.push($(this).val());
});
var jsonString = JSON.stringify(selected);
$.ajax({
type: "POST",
url: "api.php",
data: {data : jsonString},
success: function(response){
$.each(response, function(index, val) {
$("#"+index+"").html(val);
});
}
});
});
function assignallorderids()
{
var checkstatus=$("#checkall").is(":checked");
if(checkstatus==true)
{
var id=document.getElementById("ordercheckallIDs").value;
document.getElementById("orderids").value=id;
$("input:checkbox[name='checkassigneeid']").prop('checked',true);
}
else
{
$("input:checkbox[name='checkassigneeid']").prop('checked',false);
document.getElementById("orderids").value='';
}
}
function assignorderids(oid)
{
var checkstatus=$("#assigneeid-"+oid).is(":checked");
var morderId =document.getElementById("orderids").value;
if(checkstatus==false)
{
var arrayorder = JSON.parse("[" + morderId + "]");
document.getElementById("orderids").value='';
for (var i = 0; i < arrayorder.length; i++) {
var orderstatusValue=arrayorder[i];
if(orderstatusValue!=oid){
if (document.getElementById("orderids").value=='')
{
document.getElementById("orderids").value=orderstatusValue;
}
else
{
var newvalue=document.getElementById("orderids").value;
document.getElementById("orderids").value=newvalue+","+orderstatusValue;
}
}
}
}
else
{
if(morderId=='')
{
document.getElementById("orderids").value=oid;
}
else
{
document.getElementById("orderids").value=morderId+","+oid;
}
}
}
api.php
<?php
$curl_data['username']='outthinking781346';
$curl_data['password']='ouhk78epe34csmed46d';
$data = json_decode(stripslashes($_POST['data']));
foreach($data as $id){
$orderid = $id;
$curl_data['awb']=$orderid;
$response = array();
$url = 'plapi.ecomexpress.in/track_me/…'.$orderid.'&username=outthinking781346&password=ouhk78epe34csmed46d';
$ch = curl_init();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec ($ch);
curl_close($ch);
$res = explode("\n",$output);
if ( ! isset($res[13]))
{
$res[13] = null;
}
$status = str_replace('</field>.','',$res[13]);
$statusfinal = str_replace('<field type="CharField" name="status">','',$status);
if($statusfinal!='')
{
$sqlecom = "UPDATE do_order set in_transit='".$statusfinal.".',tconformed_by='Ecom' where order_id=".$orderid;
$db_handleecom = new DBController();
$resultecom = $db_handleecom->executeUpdate($sqlecom);
}
// store the responce in array
$response[$orderid] = $statusfinal;
return $response;
}
?>
table.php:
<td>
<input type="checkbox" name="assigneeid" class="assigneeid-order" value="<?php echo $orderrecords[$k]["order_id"]; ?>">
</td>
<td>
<?php echo $orderrecords[$k]["order_id"]; ?>
</td>
<td id="<?php echo $orderrecords[$k]["order_id"];?>">
</td>
in ajax call:
$('#show_status').click(function(){
var selected = [];
$('.assigneeid-order:checked').each(function() {
selected.push($(this).val());
});
var jsonString = JSON.stringify(selected);
$.ajax({
type: "POST",
url: "api.php",
data: {data : jsonString},
success: function(response){
response = $.parseJSON(response);
$.each(response, function(index, val) {
$("#"+index+"").html(val);
});
}
});
api.php:
require_once("dbcontroller.php");
$db_handle = new DBController();
$curl_data['username']='outthinking781346';
$curl_data['password']='ouhk78epe34csmed46d';
$data = json_decode(stripslashes($_POST['data']));
$response = array();
foreach($data as $id){
$orderid = $id;
$curl_data['awb']=$orderid;
$url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order='.$orderid.'&username=outthinking781346&password=ouhk78epe34csmed46d';
$ch = curl_init();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec ($ch);
curl_close($ch);
$res = explode("\n",$output);
if ( ! isset($res[13]))
{
$res[13] = null;
}
$status = str_replace('</field>','',$res[13]);
$statusfinal = str_replace('<field type="CharField" name="status">','',$status);
if($statusfinal!='')
{
$sqlecom = "UPDATE do_order set in_transit='".$statusfinal.".',tconformed_by='Ecom' where order_id=".$orderid;
$db_handleecom = new DBController();
$resultecom = $db_handleecom->executeUpdate($sqlecom);
}
// store the responce in array
$response[$orderid] = $statusfinal;
}
echo json_encode($response);
//return $response;
How we get the twitter card data from twitter when we get the twits.
my code is
libxml_use_internal_errors(true);
$page_html = new DomDocument();
$ch = curl_init();
$timeout = 500;
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
if(!empty($data)){
$page_html->loadHTML($data);
}
It is not possible to get Twitter Card data from the API.
I am using autocomplete to get suggestions from multiple sources and show them as one list in the UI. When I am typing, the suggestions show up, but when I hover over a suggestion I get an error "TypeError: n is undefined". When I click a suggestion I get an error "ui.item is undefined".
The HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Autocomplete with Multiple Search Engines Suggestions</title>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript">
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this, currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
self._renderItem( ul, item );
});
}
});
$(function(){ //page load
$("#q").focus(); //set focus to search field
$("#q").catcomplete({
source:"suggest.php",
minLength:2,
delay:10,
select: function(event, ui) {
window.location.assign(ui.item.searchUrl + ui.item.label);
//document.getElementById("q").value = ui.item.label
//$("#q").val(ui.item.value);
//$("#searchform").submit();
}
});
});
</script>
<style type="text/css">
.ui-autocomplete-category {
font-weight: bold;
font-size: 1em;
padding: .2em .2em;
margin: .4em 0 .2em;
line-height: 1.5;
color: #069;
border-bottom: 2px solid #069;
}
li.ui-autocomplete-category {
list-style-type: none;
}
</style>
</head>
<body>
<form id="searchform" name="form1" method="get" action="http://www.google.com/search">
Search:
<input name="q" id="q" type="text" size="40" />
<input name="submit" type="submit" value="Search" />
</form>
</body>
</html>
The PHP-script:
<?php
//Search term
$term = $_REQUEST['term'];
//Search Engine array
$searchEngines = array(
"Google" => array("http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&q=", "http://www.google.com/search?q="),
//"Bing" => array("http://api.bing.com/osjson.aspx?query=", "http://www.bing.com/search?q="),
//"Yahoo" => array("http://ff.search.yahoo.com/gossip?output=fxjson&command=", "http://search.yahoo.com/search?p="),
"Wikipedia" => array("http://en.wikipedia.org/w/api.php?action=opensearch&search=", "http://en.wikipedia.org/w/index.php?title=Special%3ASearch&search="),
//"Ebay" => array("http://anywhere.ebay.com/services/suggest/?q=", "http://shop.ebay.com/i.html?_nkw="),
"Amazon" => array("http://completion.amazon.com/search/complete?search-alias=aps&client=amazon-search-ui&mkt=1&q=", "http://www.amazon.com/s/field-keywords=")
);
//Combine Search Results
$searchArray = array();
foreach($searchEngines as $engine => $urls){
$url = $urls[0] . rawurlencode($term);
try{
//$json = file_get_contents($url);
$json = get_url_contents($url);
$array = json_decode($json);
$array = $array[1]; //$array[1] contains result list
if(count($array) > 0){
$array = getFormattedArray($array, $engine, $urls[1]);
$searchArray = array_merge($searchArray, $array );
}
} catch (Exception $e){ /* Skip the exception */ }
}
//Output JSON
header('content-type: application/json; charset=utf-8');
echo json_encode($searchArray); //Convert array to JSON object
//Format array to add category (search engine name)
function getFormattedArray($array, $engine, $searchUrl){
$newArray = array();
foreach($array as $a){
$newArray[] = array('label' => $a, 'searchUrl' => $searchUrl, 'category' => $engine);
}
return $newArray;
}
//Read URL contents
function get_url_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$ip=rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/".rand(3,5).".".rand(0,3)." (Windows NT ".rand(3,5).".".rand(0,2)."; rv:2.0.1) Gecko/20100101 Firefox/".rand(3,5).".0.1");
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
?>
I am adding this as a comment, not an answer, for the moment and I plan to update it as we get through the issue.
First, I was able to replicate your code and the error here: https://jsfiddle.net/xatu48sc/2/
I am using the regular (non minified) version. I encountered the error on Line 5836:
5826 item = ui.item.data( "ui-autocomplete-item" );
5827 if ( false !== this._trigger( "focus", event, { item: item } ) ) {
5828
5829 // use value to match what will end up in the input, if it was a key event
5830 if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
5831 this._value( item.value );
5832 }
5833 }
5834
5835 // Announce the value in the liveRegion
5836 label = ui.item.attr( "aria-label" ) || item.value;
5837 if ( label && $.trim( label ).length ) {
5838 this.liveRegion.children().hide();
5839 $( "<div>" ).text( label ).appendTo( this.liveRegion);
5840 }
The error I see is:
TypeError: item is undefined jquery-ui.js (line 5836, col 13)
This tells us that item is not defined, thus item.value is undefined, and so I included the code before where it's initiated. This will point us back to your custom widget to render categories.
When I compare that to the example at https://jqueryui.com/autocomplete/#categories I can see a number of differences. There is no _create method and in the _renderMenu method, there is no li defined for items.
Somewhere in here is where the problem lies.
I have also found that this error is only thrown for items that have no category.
UPDATE
I found the issue in your code by using a Text Compare site. Here is the issue:
self._renderItem( ul, item );
The command in the example page is:
li = that._renderItemData( ul, item );
It's not using _renderItem(), but what appears to be an undocumented extension point: _renderItemData()
Base on this: Difference between jQuery autocomplete renderItem and renderItemData you are using the extension point correctly.
When I make this minor change to your code, it works without error:
$.widget("custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function(ul, items) {
var self = this, currentCategory = "";
$.each(items, function(index, item) {
var li;
if (item.category != currentCategory) {
ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
currentCategory = item.category;
}
li = self._renderItemData(ul, item);
});
}
});
Working example: https://jsfiddle.net/xatu48sc/6/
I suspect there is a scope issue between the two. If this is not good and you really want to use _renderItem() then I can look into it. Using _renderItemData() does work.
May be am creating a lot of confusion with the previous post, so am trying redesign my entire post with my requirement and effort.
I want to fetch GMAIL contact list using PHP, to achieve this I have done the following thing:
Create Google Client ID with oAuth 2.0 protocol
Create 2 PHP files (oAuth.php and index.php)
Here is the code for 2 files:
oAuth.php:
<html>
<head>
<meta name="robots" content="noindex" />
<title>Email address list - Import Gmail or Google contacts</title>
<style type="text/css">
a:link {color:Chocolate;text-decoration: none;}
a:hover {color:CornflowerBlue;}
.logo{width:100%;height:110px;border:2px solid black;background-color:#666666;}
</style>
</head>
<body>
<div class="logo" >
</div>
<br/>
<div><b>Visit Tutorial: </b><a style="font-size:17px;" href="" >Import Gmail or Google contacts using Google Contacts Data API 3.0 and OAuth 2.0 in PHP</a></div>
<br/>
<div style="padding-left: 50px;">
<?php
$client_id = '1041526369396-kmnbhsos616eqcqimjrs07icn2c176ln.apps.googleusercontent.com';
$client_secret = '*************';
$redirect_uri = 'https://www.test.multicon.in/test9/oauth.php';
$max_results = 25;
$auth_code = $_GET["code"];
function curl_file_get_contents($url)
{
$curl = curl_init();
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
curl_setopt($curl,CURLOPT_URL,$url); //The URL to fetch. This can also be set when initializing a session with curl_init().
curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,5); //The number of seconds to wait while trying to connect.
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); //The contents of the "User-Agent: " header to be used in a HTTP request.
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header.
curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect.
curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); //To stop cURL from verifying the peer's certificate.
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$contents = curl_exec($curl);
curl_close($curl);
return $contents;
}
$fields=array(
'code'=> urlencode($auth_code),
'client_id'=> urlencode($client_id),
'client_secret'=> urlencode($client_secret),
'redirect_uri'=> urlencode($redirect_uri),
'grant_type'=> urlencode('authorization_code')
);
$post = '';
foreach($fields as $key=>$value) { $post .= $key.'='.$value.'&'; }
$post = rtrim($post,'&');
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'https://accounts.google.com/o/oauth2/token');
curl_setopt($curl,CURLOPT_POST,5);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
$result = curl_exec($curl);
curl_close($curl);
$response = json_decode($result);
$accesstoken = $response->access_token;
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&oauth_token='.$accesstoken;
$xmlresponse = curl_file_get_contents($url);
if((strlen(stristr($xmlresponse,'Authorization required'))>0) && (strlen(stristr($xmlresponse,'Error '))>0))
{
echo "<h2>OOPS !! Something went wrong. Please try reloading the page.</h2>";
exit();
}
echo "<h3>Email Addresses:</h3>";
$xml = new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
foreach ($result as $title) {
echo $title->attributes()->address . "<br>";
}
?>
</div>
</body></html>
And index.php
<html>
<head>
<meta name="robots" content="noindex" />
<title>Import Gmail or Google contacts using Google Contacts Data API 3.0 and OAuth 2.0</title>
<style type="text/css">
a:link {color:Chocolate;text-decoration: none;}
a:hover {color:CornflowerBlue;}
.logo{width:100%;height:110px;border:2px solid black;background-color:#666666;}
</style>
</head>
<body>
<div class="logo" >
</div>
<br/>
<div><b>Visit Tutorial: </b><a style="font-size:17px;" href="http://test.multicon.in/test9/" >Import Gmail or Google contacts using Google Contacts Data API 3.0 and OAuth 2.0 in PHP</a></div>
<br/><br/>
<div align="center" >
<a style="font-size:25px;font-weight:bold;" href="https://accounts.google.com/o/oauth2/auth?client_id=1041526369396-kmnbhsos616eqcqimjrs07icn2c176ln.apps.googleusercontent.com&redirect_uri=https://www.test.multicon.in/test9/oauth.php&scope=https://www.google.com/m8/feeds/&response_type=code">Click here to Import Gmail Contacts</a>
</div>
</body>
</html>
Now while clicking on the links in index.php it shows me that the My Project wants to access my Gmail contact...but when it takes me to the redirected page...it shows page not available whereas that page is there. I don't know whether am clear to you or not...if possible please check the link http://test.multicon.in/test9/index.php may be this will help you to understand my problem
finally...I have resolved this issue, the my domain was not added with WWW records, that's why I was getting the error "DNS_PROBE_FINISHED_NXDOMAIN", the moment I have added the WWW records for test.multicon.in,the error resolved
I have a script for YouTube which allows me or anyone else to use on a site to upload videos directly to a YouTube account.
The problem is only the video is uploaded with no video information such as title & description I want the person who is uploading the video to have the options of filling in a form which will then result in the title & description on YouTube.
The script can be seen at the bottom. What I want is for a form to be in place which is something like the following:
Video Title: Cat Drives Car
Video By: MrShoez
Video Description: Watch this video of a cat driving a car.
And the title output would be something as "Cat Drives Car by MrShoez"
Along with the description displaying: This video was submitted on DATE HERE by MrShoez. "Watch this video of a cat driving a car."
*
<?php
$youtube_email = "email#address.com"; // Change this to your youtube sign in email.
$youtube_password = "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));
$youtube_video_title = "VIDEO TITLE"; // This is the uploading video name.
$youtube_video_description = "VIDEO DESCRIPTION"; // This is the uploading video description.
$youtube_video_category = "CATEGORY"; // This is the uploading video category.
$youtube_video_keywords = "tags, tags, tags, tags"; // 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>
<yt:private/>
<media:title type="plain">'.$youtube_video_title.'</media:title>
<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 = "UNIQUEKEY HERE"; // 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);
?>
<script type="text/javascript">
function checkForFile() {
if (document.getElementById('file').value) {
return true;
}
document.getElementById('errMsg').style.display = '';
return false;
}
</script>
<?php
$nexturl = "http://website.com/directurl"; // This parameter specifies the URL to which YouTube will redirect the user's browser when the user uploads his video file.
?>
<form action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($nexturl)); ?>" method="post" enctype="multipart/form-data" onsubmit="return checkForFile();">
<input id="file" type="file" name="file"/>
<div id="errMsg" style="display:none;color:red">
You need to specify a file.
</div>
<input type="hidden" name="token" value="<?php echo($response->token); ?>"/>
<input type="submit" value="go" />
</form>
</php>
*