I need to upload a video to YouTube but without the video being on my web server. I have videos on a separate storage server, and the PHP is on a web server, I understand and got it working to upload a video to YouTube which is in my public web server folder.
It's simply as you only need to provide the location of the file, like $videoPath=sfConfig::get('sf_root_dir').'/web/tmp.mp4', however, going on with this code my web server would have to download the file from my storage server and then set the path of the video, but that would lead to too much bandwidth usage of my web server. What I'd like to do is something like $videoPath="http://storageserverurl.com/tmp.mp4" but that isn't possible.
Here is the piece of code that downloads the file to the web server and sends it to YouTube, it's working without problems.
file_put_contents("tmp.mp4", file_get_contents("http://storageserver.com/tmp.mp4"));
$videoPath=sfConfig::get('sf_root_dir').'/web/tmp.mp4';
I'd like it to be something like $videoPath="http://storageserver.com/tmp.mp4";
The rest of the code is the sample code given by Google. I'm using PHP 5.6.3 with symfony 1.4.
Related
Hope you are doing well .
I’m working currently on a project that gets mp3 content from Google Cloud Storage into a web application to be played for users .
I just wanna know how I can get those audio files on streaming without downloading them in my project repo .
One approach is using a public Url , but I think that is not secure because people who know the url can access all my files stored in the cloud ?
I'm using php laravel
The only approach to this case I think is to use Signed URLs because we don't know whether they have a Google account.
Another solution that download the file locally on the server, and then let the user download the file from the server.
from this article https://support.google.com/drive/answer/2881970?hl=en . google doesn't support web hostings. Is there any way that i can get my image from googledrive for example like this:
for example i have a shared folder like this:
https://drive.google.com/drive/folders/0ByzxsoB7kICPUjVEVG12a0hNSWc
and that shared folder contains with
myimage1.jpg,
myimage2.jpg,
myimage3.jpg,
i want to select/change it in my website by using that image.
For example i uploaded another image in my googledrive to replace my web image easily. Please help.
something like this :
<img src = "googledriveimage/myimage1.jpg">
after i want to replace the image. then i would go to googledrive and replace the myimage1.jpg with another image but the same file name.
You could write a PHP script to fetch the desired image from google drive and return it back to the HTTP client.
Refer to the flow in the diagram:
User views the HTML page in his/her browser
The browser sends a HTTP GET request to your PHP script.
The PHP script is hosted either in a publicy accessible web server (or uses a cloud service provider e.g. Google App Engine, you could use any cloud hosting service provider). The script would use the Google Drive SDK to use OAUTH and request the pre-specified image file from Google Drive. Here, you need to use either the SDK or wrap the request in the proper JSON/XML format as specified by Google Drive API. You need to embed the desired logic of translating a front-end visible image filename to the real Google Drive filename.
Google drive translates the request, checks authentication and retrieves the image.
The image is returned back to the PHP script.
The PHP script encodes the image and sets the right MIME type, headers, etc.
The user is able to view the image on the page.
To clarify, you dont need to host your PHP script in Google App Engine, you could host it on any other web hosting provider infrastructure.
I've used Google drive APIs in servlets deployed on Google App engine. I haven't used PHP in GAE, but have quoted the PHP references since you indicated familiarity with PHP. If you're interested in using GAE, first read the concepts related to GAE here https://cloud.google.com/appengine/docs/php/concepts and then the PHP how-tos for using the SDK and deploying the app using PHP - https://cloud.google.com/appengine/docs/php/how-to . Also refer to this documentation - https://cloud.google.com/appengine/docs/php/ .
I've included the concept of how you can solve your problem, you need to go through the documents and implement this yourselves.
I am working to create a script that scans our company Google Drive folders and copies any new files into a Repository directory on my server.
So far I can connect to GDrive, read all files, edit files, but I am unable to download via PHP. copy() file_get_contents() file_put_contents() etc. Are not working.
I imagine the solution is to use Google Apps Script to download and copy the file to my server directory, but I do not see the correct class.methods in the documentation.
How can I copy a GDrive file to my server using Google Apps Script?
You could run some code through Google Apps Script to upload the files to your server. In that case you need to use UrlFetchApp.fetch, which despite its name can also do an HTTP POST with arbitrary data. There is an example for uploading files in the API documentation.
https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
So far, I've built a PHP script that downloads to a remote server of mine a file from Internet, provinding its URL (I've used this piece of code to download to the server).
Now I would like to upload the downloaded file on Google Drive using its API.
My question is: Is there a way to download the file directly to Google Drive, without using the server? Or I am forced to download the file first to the server and then upload it to Google Drive?
Thank you
I doubt if you can 'make' google drive get file from an external location...
However you do have an option to create a shortcut to the external file, if that suits you.
Also, If you wish continue direct upload you may refer this.
As far as I know the API doesn't allow to push files from another referer than the one that's calling the API. So, long story short:
First you need to download the file to your server, then upload it to gDrive from your server.
Read here more: https://developers.google.com/drive/examples/php#saving_files
Or here: https://developers.google.com/drive/manage-uploads
I'm making my own website using html and php, and a database using mysql on localhost on a easyPHP server. Users can make an account and upload videos on the site.
I'm wondering if it would be possible when they upload the file, it would upload the file to youtube and I can just save that link in my database. Then on the content page I could just use that link to show the video in an embedded player.
If that's not possible, what would be the best way to save the content in a folder on my PC?
Thanks
Yes, Youtube allows uploading video files directly to Youtube's servers, bypassing your server.
This page documents it pretty well: https://developers.google.com/youtube/2.0/developers_guide_protocol_browser_based_uploading