PHP Youtube downloader API Download file name videoplayback - php

I am using Youtube download API when i click on download button video is downloading but filename showing "videoplayback.MP4"
My code:
<?php
$url="http://hddir.com/ajax/api.php?type=downlink&v=Is3S-6hHQLk";
$c=curl_init();
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
curl_setopt($c,CURLOPT_URL,$url);
$contents=curl_exec($c);
curl_close($c);
$someObject = json_decode($contents);
foreach($someObject as $obj){
$url=$obj->url;
$format=$obj->format;
echo '<a href="'.$url.'" download>video '.$format.'</a></br>';
}
?>
Result result of above code

As a quick fix, HTML5 provides a download attribute you may use in your anchor tag, this allows you to specify the desired file name of the download. This relies on the end user using a browser which supports this tag.
echo 'video '.$format.'</br>';
At the time of writing browser support is:
Chome: 14.0
Edge: 13.0
Firefox: 20.0
Safari: 10.1
Opera: 15.0
There is no requirement to specify a file extension.
More information can be found online including browser support, for example this W3 Schools Article
Update: This will not work cross-origin, the file must be hosted on the same domain, as such this is not a solution for this particular problem unfortunately.

Related

How to get video download link from Google Drive in PHP?

I'm trying to get the download source from a Google Drive file I own. I currently have this code:
$videoSRC = "https://www.googleapis.com/drive/v3/files/". $_GET['id']. "?alt=media&key=API_KEY_HERE";
echo '<video autoplay="" preload="auto" src="'. $videoSRC. '"></video>';
The problem is, when you look at the video source, it says the video source is "https://www.googleapis.com/drive/v3/files/GOOGLE_FILE_ID?alt=media&key=API_KEY_HERE". While it does display the video, I've seen that website have their video source as "https://redirector.googlevideo.com/videoplayback". How are they able to achieve this?
I suggest using the webContentLink of the file which is generated by using the Files.get.
Files.get uses the following URI request:
https://www.googleapis.com/drive/v3/files/fileId
Tried this on one of my file and got this webContentLink:
https://docs.google.com/uc?id=0Bzgk4zccNwI7MmJOYWs3SG1VUUE&export=download
You can pass this link in your GET request in PHP and see if it downloads the file.

Sending an audio file path to email and there by playing the audio in jwplayer when clicked on link

One of my friend sent me an email. It contains a path to audio file.
When i click on the link the audio starts playing (only if it is .mp3 format) in chrome.
This is not the case every time A user may send any kind of format Ex: aac,m4a etc.
So i would like to play the audio in a jwplayer
On clicking the url the audio must be able to play in the browser using jwplayer.
The path to the audio file is bitle generated short url.
I downloaded jwplayer files and source code from http://www.longtailvideo.com/players/jw-flv-player/ and i set up my player accordingly to document. But still facing the problem
Kindly give suggestions.
JWPlayer is nice but it lacks a good interface. I have been able to embed jwplayer into prettyphoto and that has solved a lot of issues for me.
There is an article that describes how to do this located at http://forums.no-margin-for-errors.com/discussion/5671/how-to-integrate-jwplayer-in-prettyphoto-with-flash-and-html5/p1
Once you get that working my suggestion would be for the url to contain GET vars that include the filename to be played. Use PHP to create an href that will trigger prettyphoto/jwplayer to open and play the file.
Also, the instructions on the link I gave you did not work for me. I had to modify them but here is the code that got it to work:
case 'jwplayer':
pp_dimensions = _fitToViewport(movie_width,movie_height); // Fit item to viewport
controlbar_height = 29; //Allow for JWplayer's bar
pp_dimensions['height']+=controlbar_height;pp_dimensions['contentHeight']+=controlbar_height;pp_dimensions['containerHeight']+=controlbar_height;
jwplayer_settings = {flashplayer: '/jwplayer/player.swf', controlbar: 'bottom', skin: '/jwplayer/jwplayer_skin.zip', autostart: true, id: 'jwplayer1'};
jwplayer_settings.width = pp_dimensions['width'];
jwplayer_settings.height= pp_dimensions['height'];
jwplayer_settings.file = pp_images[set_position];
skipInjection = true;
/* include jwplayer JS embedder */
$.getScript('/jwplayer/jwplayer.js', function() {
jwplayer("pp_full_res").setup(jwplayer_settings);
_showContent();
});
break;

Open Word document in browser (Google Chrome) instead of downloading (with PHP)

Is there way to tell browser (i care mainly about Google Chrome which looks to have "Microsoft Office 2010" plugin) to open Microsoft Word document inside of browser using PHP?
RESULT: all tries made browser to download file. Looks like this Chrome plugin serves for something else than rendering .doc files.
Try setting the Content-Disposition to inline
header("Content-Disposition", "inline;filename=somefile.ext")
Yes. Set the MIME type properly and then set the Content-Disposition header to inline.
<?php
header('Content-Disposition: inline; filename=blah.doc');
?>
You could create redirect to google docs viewer with URL of the file in GET request.
For example, if you wanted to view the PDF at the URL http://research.google.com/archive/bigtable-osdi06.pdf , you would use the URL: http://docs.google.com/viewer?url=http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf

Provide file download webpage without server side code

Lets say i have this string "something1,something2" and i want to download it as "text.csv", without opening new window (pop up) how could i do this from a webpage. can i dot it in JS without using this:
window.open('data:text/csv;charset=utf-8,' + str);
or do i have to use PHP for this ?
What you want to do is a bit unconventional, but it is possible.
Take a look at Downloadify. It's a JavaScript library that leans on Flash to create a file on the client side and present the file download dialog.
David Walsh has some good demos and info too on his blog.
While limited, there is also http://en.wikipedia.org/wiki/Data_Uri
So this as a url would open an image
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
You could have javascript open this url to trigger the download
A CSV example
data:text/csv,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0A
Just copy/paste either of those into your browser to see them work. Browser support is limited.
IE 8 for example has a 32KiB limit

Codeigniter Force download IE

I am having trouble with the download helper in ie..basically I built a site that dynamically creates pdf invoices and pdf proofs in both cases the force download works great in firefox, chrome and opera. In IE it fails everytime and I get the following error:
Unable to download $filename from mysite.com
Unable to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.
To begin the force_download I have a anchor target _blank with a url that directs to the following controller:
function view_uploaded_file($order = 0, $name = NULL){
$this->load->helper('directory');
$params['where'] = array('id' => id_clean($order));
$data['order'] = $this->MOrders->get($params);
if($data['order']->id < 1){
redirect('admin/orders');
}
$name = db_clean(urldecode($name));
$map = directory_map('./uploads/customer_order_uploads/'.$data['order']->user_id.'/'.$data['order']->id, 1);
if(is_array($map) && in_array($name, $map)){
$this->load->helper('download');
$data = file_get_contents('./uploads/customer_order_uploads/'.$data['order']->user_id.'/'.$data['order']->id.'/'.urldecode($name));
force_download($name, $data);
} else {
redirect('admin/orders');
}
}
Originally I thought maybe a problem with MY IE but I am able to download PDFs on other sites. I then thought that it could be a problem with codeigniters download helper but I see they already made special provisions for IE in the helper.
If you have any ideas please let me know. Thank you.
Frankly I am not sure why we bothered with a helper for downloads in code igniter.
It's not entirely hard to do in pure php:
This Wonderful Question/Answer outlines how to do it quite nicely.
The real thing to remember is the content-disposition: attachment part of the headers. It's what tells the browser that the file should be downloaded & saved vs. trying to show it in the browser.
All browsers handle things differently, maybe you have something in your IE install that's overriding the behaviour but if you follow the instructions in the linked article, you should get files downloaded correctly in all browsers.
Essentially there are 3 things we need to tell the browser:
Content Type
File Name
How to treat the incoming data
(Optional Fourth, if you have it) File Size (Content-Length)
Then you just dump that data right out to the output buffer.
Response
In response to your replies, it's probably a security feature to not automatically download something in a popup window, probably one of the new things IE introduced to combat their previous security holes.
Well I have found atleast a temporary fix for the problem. All my links for force downloads were target _blank..once I created standard non pop out links the file downloads worked in IE. There is probably some type of work around but I just also realized there is really no need for a pop up window for the download anyway..the download dialog box already serves that purpose.

Categories