Laravel 4 Response::download() from external url source - php

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()

Related

How to upload videos as a file directly to server using Alamofire 5?

I wish to upload a video file stored on the mobile device on which the app is downloaded, to a folder within my server (ran with PHP). I am trying to use Alamofire to do this, and it said in their documentation that I should NOT use multipart form data for this as it could be too slow/memory intensive. Instead, I am using, as was recommended in the Alamofire documentation, this code to upload the video file directly to the server:
AF.upload(videoURL, to: "[string of url of my server folder]")
Here, videoURL is the local url of the video (an mp4 file) on the phone.
Now, as for the url to my server, if I just put in the the path to the folder, the return string I get just seems to scrape the HTML code of the web page that you get when you past in the link into a browser, and the file is not uploaded.
Then, if I write a path to a new file within the folder that doesn't already exist, the error message just says:
The requested URL was not found on this server.
Lastly, I have tried passing in the url of an already existing mp4 file with a video in the server folder, hoping that when I upload to this url, this video will then be replaced by my video file. However, what gets returned as a message from the server then is a very (very) long string (making Xcode very laggy) that I believe is some representation of the current video already in the file, and on the server the video has not been replaced.
So, I have tried these three different possibilities, but none of them seem to get the file uploaded to the server. Do you have any idea what the problem is? Do I need to do something server side, with PHP code, or is it fine as it is just trying to upload the video like this? According to what I could find in the documentation, this seems to me like it should be ok.
Link to documentation: https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md

Can I define a folder where to download to, using force_download()?

I'd need to define a folder where a downloaded files is placed.
Is it possible to achieve a download into a specific folder using the force_download() function, of Codeigniter's framework?
force_download() is part of CI download helper
Generates server headers which force data to be downloaded to your
desktop. Useful with file downloads. The first parameter is the name
you want the downloaded file to be named, the second parameter is the
file data.
that said, a file will be downloaded to your designated download folder, wherever that is on your local disk. You can use this approach to make files downloadable for any user
what you are looking for is to use the CI FTP Class:
Downloads a file from your server. You must supply the remote path and
the local path, and you can optionally set the mode. Example:
$this->ftp->download('/public_html/myfile.html', '/local/path/to/myfile.html', 'ascii');
you must make sure that each time you call this to have the user supplying you with a valid local path, where the downloaded files will be stored.

How to access a video file in a directory located in my server's home directory

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.

Display absolute links to downloaded files via youtube-dl?

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.

Download file via PHP from FTP, like normally downloading a file?

I am currently trying to retrieve a file from an FTP-Server in order to make it accessible for the user to download. ftp_get() writes it to a path on the local machine, yes, but what I want is that it also shows up in the download history and counts as "normal" download from the internet but I didn't figure out how to do this yet. I also tried to link directly to the file in PHP with header("Location: ftp://username:password#ftp.server.com/myfile.file") but this was resulting in the browser showing the files contents (which I didn't want). Did I miss any header-Parameters ? Or is there a completely different way to do this ?
You won't be able to "redirect" a user to a file so he can download it using FTP. This is a HTTP-thing. Browsers provides FTP features and make it look like HTTP but, in fact, those are different stuff.
If this file is only accessible through FTP and it is on a remote server, the only way I can imagine so you cand 'redirect' this download to the user is:
Download the file from the FTP to your application server through FTP in PHP;
Send it to the user using PHP and appropriate file headers, something like this: https://stackoverflow.com/a/7263943/2802720
Hope it helps.

Categories