I've set up youtube-dl on my shared Debian 3 host so I can access it via an URL to pass address to what I want to download so it would download it on my host.
I was wondering if there is a way to display URL links to file(s) downloaded by last request on a web page for easier download.
So for example, if you call domain.com/youtubedl.php?url=www.youtube.com/watch?v=000000 would download it and then display this on the page:
http://domain/download_directory/youtubefile.mp4
so you can easily download it by clicking on that link.
Thanks
By default, the video will be saved in the current operating directory of the script which has called youtube-dl. The default filename is videoname-videoid.extension. For example, I downloaded this video with the name "PHP Programming" and the video ID of "7TF00hJI78Y". When it was downloaded, it was in the directory of my batch file which I used to call youtube-dl, and was called "PHP Programming-7TF00hJI78Y.mkv". The extension can be defined as per the following information from youtube-dl's Git-Hub page. I would suggest not leaving the files in this directory, however, keeping youtube-dl outside of the public website directory, and moving the video files through your script to a public directory for downloads.
Related
I have a Laravel App that can upload file to a folder.
The folder is a symlink to /media/folder_name, that is a mount point of a Windows share (mounted via fstab).
Upload and Download works.
The download action returns a copy of the file:
return response()->file($path_file);
I want that the download action to show me the original file (saved in windows folder, like: //192.168.1.2/share/folder/file.pdf).
It is possible?
After some research, direct link to local resource is denied in Firefox and Chrome for security reasons.
So, the solution is to install the Local Filesystem Links extension for firefox. In Laravel, return a blank page with the link to the resource, like: file:////192.168.1.2/folder/file.pdf.
Finally, when you click the pdf link, the original resource is opened with the default program (Adobe Reader, for example).
Unable to correctly use php code to load a video mp4 file stored in home directory.
Hi, I am building a WP site that sells instruction video mp4 files. To protect the files I have placed them in a directory called videos which is in the home directory (outside of the public_html directory) to protect the files from being downloaded for free. I am trying to write php code for loading the video. However, I can't access the video in /home/username/videos.
My code:
add_action('template_redirect', 'video_redirect', 5);
function video_redirect(){
if (is_admin())
return;
if (!is_page(videoplayerpageonmysite))
return;
$filename="/home/username/videos/videofile.mp4";
echo " Your browser does not support the video tag.";
Each time I run the code I get a No video with supported format... error.
I'm only able to get it to load the video file when it is in the public_html folder (it works perfectly then), but not when it is located in /home/username/videos/
Please help!
You can't give the browser a file path on your server's hard disk and expect it to be able to load it. It will resolve it as a relative URL, ask the HTTP server for it, and then get a 404.
You need to give the browser a URL that actually loads the file.
If you want to limit who can access it (e.g. people who have paid), then you could write a PHP program that checks to see if the request is coming from someone who has paid (i.e. Authentication + Authorization), then reads the file and outputs it in the HTTP response.
You have to use a PHP script as the source URL in the video tag and specify some identifier for which video it should load e.g. src="loadvideo.php?id=1" or something. (This is because the source must be a valid URL which is actually accessible on the webserver - the browser, which don't forget runs on the user's machine not the server, cannot navigate to a path on disk. If it could, then moving your files outside the public_html folder would not provide any security!)
And then when the video tag is loaded into the page, it will make a request to that URL, which causes the PHP script to run. The script must associate the provided ID with the correct file on disk, fetch the contents of that file and echo them as the response, along with appropriate headers (e.g. mime type etc). You can probably find examples of this pattern online already.
Of course the PHP script will also need to authenticate the request to make sure the requestor is a signed-in, paid user, otherwise you still aren't protecting anything. Without this last step, anyone could just visit the PHP script's URL and provide an ID until they got a result, and download the videos just as if you'd put them in the public_html folder. As long as you implement security correctly though, only users who already paid for the videos would be able to download them.
If I place video file to for example
www.myweb.com/webroot/video.mp4
I am able to play it in VLC player in streaming option. I am using CakePHP 3 framework.
Where this file is placed in
/volume1/web/myweb/webroot/video.mp4.
But my question is how do I create link to file which is in Synology NAS, its link is:
'/volume1/video/Films/video.mp4'
To be accessible from a web?
I added to open_basedir in PHP in a directory :/volume1/video;
Instead of pointing to the actual file, have you tried reading the file using a PHP script?
For example, your site could have a link such as yoursite.com/video.mp4, but instead, you could have yoursite.com/getfile.php?f=video.mp4.
This getfile.php script can securely get the file from anywhere in your file server where your www user has access.
I personally use the readfile_chunked function documented here in the comments, as well as the appropriate headers needed to be sent before.
Note: Make sure you secure your getfile.php script to prevent users from reading any files on your drive. In my case, I force my script only to accept certain keys which correspond to actual files (ex: yoursite.com/getfile.php?filekey=Ab183Fca82, where Ab183Fca82 points to video.mp4)
I can't seem to find out whether it is possible to create a download link via Response::download() method with an external URL file source instead of local file path. For example:
Response::download('https://s3.amazonaws.com/bucket/file.zip','Download.zip');
I'm hosting my static and upload file on Amazon S3 and would like to create a download link when the requested users have access to it. All I get from the testing above is a FileNotFoundException error popping up stating that file does not exist.
As #James Binford said in the comments, it is not possible to use Response::download() for files on an external source. It may not be perfect, but you can always redirect to the URL
Redirect::away('https://s3.amazonaws.com/bucket/file.zip');
Depending on the file type it will open as "normal" download (e.g. zip files) or, if the browser supports it, the contents of the file will be displayed (e.g. images or text files)
Alternatively you can download the file from the server to the application server (e.g. using curl) and then use Response::download()
I am trying make a php script to list the files of a folder above my web directory...I follow a small thing I found here which talked about
a symlink pointing to /var/uploads
a Apache Alias directive Alias /uploads /var/uploads
I did both of these.
$myDirectory = opendir("/var/stuff/stuff/");
That directory there links to like when I go in winscp and click that folder it directs me to it....and when I run my script to list all files inside /var/stuff/stuff/ it lists what is in /home/stuff/stuff.
The thing is when I click the links that it produces I get a not found on the server
The requested URL /stuff was not found on this server.
Would someone please be able to assist me with this?
Since the files are not under the root directory, you will not be able to download them directly, but What you can use for this issue is to create a downloader gateway.
I'll explain:
create a php script somewhere in your app, lets call it downloader.php
the downloader script would get a parameter, lets say: filename
now we could call the script like: http://YOUR-URL/downloder.php?filename=file-to-download
in your downloader.php file you can get the file name, read it from the file system, then force it to be downloaded by out puting its content and configure the correct headers
I'm not sure if you still need that but, if you need more assistance I can help you more with some code samples
ideally you can use .htaccess to hide your downloader gateway script