Skip to content

Instantly share code, notes, and snippets.

@Sekaiichi
Created September 15, 2019 12:18
Show Gist options
  • Save Sekaiichi/38d4ed6fc3e46b4f3d93fb4833753818 to your computer and use it in GitHub Desktop.
Save Sekaiichi/38d4ed6fc3e46b4f3d93fb4833753818 to your computer and use it in GitHub Desktop.
<?php
namespace App;
Class Download{
private function downloadFile($title, $link, $saveLink, $folderName, $i)
{
ob_start();
$nameOld = $link . $title . $i .'.mp4';
$saveLink = $saveLink . $folderName . '/' . $title . $i .'.mp4';
file_put_contents($saveLink, fopen($nameOld, 'r'));
set_time_limit(0);
/*header('Connection: Keep-Alive');
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header("Content-Disposition: attachment; filename=lesson1");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($saveLink));
while (ob_get_level()) {
ob_end_clean();
}
readfile($saveLink);*/
//unlink($saveLink);
}
private function existFolder($folderName){
if (!is_dir($folderName)){
mkdir($folderName, 0700);
return true;
}
return true;
}
public function downloadAll($start, $end, $title, $link, $saveLink, $folderName)
{
$this->existFolder($folderName);
for ($i = $start; $i < $end; $i++) {
$this->downloadFile($title, $link, $saveLink, $folderName, $i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment