I want to download a proxylist with curl in php - php

I want to download a proxy list with this api:
https://api.proxyscrape.com?request=getproxies&proxytype=http&timeout=5000&country=US&anonymity=elite&ssl=yes
how can I do it in php with curl???
When you open this url, It will automatically download a text file with proxies.
I want to download and place it in the current directory.

The easiest way would be using file_get_contents() function built into PHP.
So to download & save the file you would do something like this:
$proxies = fopen("proxies.txt", "w");
fwrite($proxies, file_get_contents('https://api.proxyscrape.com?request=getproxies&proxytype=http&timeout=5000&country=US&anonymity=elite&ssl=yes'));
fclose($proxies);

Related

How to download file Using PHP that has delayed force download?

I am at a situation, where I need to download files from the URL, it is easy with the direct file URLs like https://somedomain.com/some-path/somefile.exe
file_put_contents( $save_file_loc, file_get_contents($url_to_download);
But what to do when you have delayed force download from the URL which actually prints HTML and how to differentiate those URL?
Example URL: https://filehippo.com/download_mozilla-firefox-64/post_download/
EDIT: On above url the file download starts using JS, as I tested with blocking JS and download did not start.
Thanks in advance for your help.
Read the html of the URL using file_get_contents
Find the URL of the file within the HTML. You'll have to visit the page and view source to locate the URL. In your example of https://filehippo.com/download_mozilla-firefox-64/post_download/ it's found in between data-qa-download-url="https://dl5.filehippo.com/367/fb9/ef3863463463b174ae36c8bf09a90145/Firefox_Installer.exe?Expires=1594425587&Signature=18ab87cedcf3464363469231db54575665668c4f6&url=https://filehippo.com/download_mozilla-firefox-64/&Filename=Firefox_Installer.exe"
As you may have noticed, the page may have pre-approved the request so it's not guaranteed to work if the host has checks using cookies or other methods.
Create a regex based on the above to extract the URL using preg_match
Then file_get_contents the URL of the file to download it.

Download .mp4 from URL using Laravel

How to download .m4v video from given URL with Laravel? I have a URL for example rtmp://123456.r.cdnsun.net/_definst_/mp4:123456/h264/123456.m4v ... Can you recommend me a package for Laravel which could make the process easier?
It depends on what exactly you're trying to achieve. For example, if you want to just copy file from a remote server, you could use copy():
$remoteFile = 'rtmp://123456.r.cdnsun.net/_definst_/mp4:123456/h264/123456.m4v';
$localFile = storage_path().'movies';
copy($remoteFile, $localFile);
You can use file_put_contents to download video from URL
$video_name="video_name.mp4";
$video_path=public_path('videos').'/'.$video_name; // path where you want to store video
file_put_contents($video_path, fopen($file, 'r'));

Download multiple .csv file separately generated by PHP Script

I am running PHP Script using CodeIgniter Framework to generate user's and it's devices informations; Two different files are generated with help of
csv_from_result($user_query, $delimiter, $newline);
function of $this->load->dbutil();.
When i use
$this->load->helper('download');
library to download above .csv file using
force_download($user_file_name, $usercsvdata);
function it downloads first .csv file only, the second file is not downloaded which is of User's Devices.
Please help me to Solve this.
Thanks.
CodeIgniter has a Zip file library build in. In order to download multiple files at the same time, they have to be added to an archive, like a .zip file.
<?php
//.. get $usercsvdata and $devicecsvdata
$this->load->library('zip');
$this->zip->add_data('users.csv', $usercsvdata);
$this->zip->add_data('devices.csv', $devicecsvdata);
$this->zip->download($user_file_name);

Download and rename a file via url with PHP

I have this URL
www1.intranet.com/reportingtool.asp?settings=var&export = ok
There I can download a report. The file-name of the report includes a timestamp. e.g. 123981098298.xls and varies everytime I download it.
I want to have a script with this functions:
<?php
//Download the File
//rename it to **report.xls**
//save it to a specified place
?>
I don't have any idea after searching stackoverflow and googling on this topic :(
Is this generally possible?
The simplest scenario
You can download the report with file_get_contents:
$report = file_get_contents('http://www1.intranet.com/reportingtool.asp?...');
And save it locally (on the machine where PHP runs) with file_put_contents:
file_put_contents('/some/path/report.xls', $report);
More options
If downloading requires control over the HTTP request (e.g. because you need to use cookies or HTTP authentication) then it has to be done through cURL which enables full customization of the request.
If the report is large in size then it could be directly streamed to the destination instead of doing read/store/write in three steps (for example, using fopen/fread/fwrite).
This may not work depending on your security settings, but it's a simple example:
<?php
$file = file_get_contents('http://www1.intranet.com/reportingtool.asp?settings=var&export=ok');
file_put_contents('/path/to/your/location/report.xls', $file);
See file_get_contents and file_put_contents.

Download file through a server to user

There is a file located on a server. Lets call it "Movie".
My site's users need to downoad this movie, but the movie can only be downloaded by my website's IP.
Is there a way to download Movie to my server and from there to the user?
I can do that by "put_content" but I need the client to download the file WHILE my server downloads it.
Thanks!
You can make use of the standard wrappers PHP offers­Docs and combine that with stream_copy_to_stream­Docs:
Example / Demo:
<?php
$url = 'http://example.com/some.url';
$src = fopen($url, 'r');
$dest = fopen('php://output', 'w');
$bytesCopied = stream_copy_to_stream($src, $dest);
Related (couldn't find a better duplicate so far):
Remotely download a file from an external link to my server - download stops prematurely
Take a look at the readfile function.
http://php.net/manual/en/function.readfile.php

Categories