Skip to content

Commit

Permalink
5.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
aliyilmaz committed Apr 15, 2023
1 parent 8036edd commit 2129944
Showing 1 changed file with 27 additions and 73 deletions.
100 changes: 27 additions & 73 deletions Mind.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
*
* @package Mind
* @version Release: 5.6.3
* @version Release: 5.6.4
* @license GPL3
* @author Ali YILMAZ <[email protected]>
* @category Php Framework, Design pattern builder for PHP.
Expand Down Expand Up @@ -4681,90 +4681,44 @@ public function upload($files, $path, $force=false){
return $result;
}

/**
* File downloader.
/**
* It helps to copy files or files
*
* @param mixed $links
* @param array $opt
* @param mixed $sources
* @param mixed $destinations
* @return array
*/
public function download($links, $opt = array())
{

$result = array();
$nLinks = array();

if(empty($links)){
return $result;
}

if(!is_array($links)){
$links = array($links);
}

foreach($links as $link) {
public function duplicate($sources, $destinations){
$result = [];

if($this->is_url($link)){
if($this->remoteFileSize($link)>1){
$nLinks[] = $link;
}
}

if(!$this->is_url($link)){
if(!strstr($link, '://')){

if(file_exists($link)){
$nLinks[] = $link;
}

}
$destinations = (isset($destinations)) ? (!is_array($destinations) ? [$destinations] : $destinations) : null;
if(!is_null($destinations)) {
foreach ($destinations as $destination) {
if(!is_dir($destination)){ mkdir($destination, 0777, true); }
}

}

if(count($nLinks) != count($links)){
return $result;
}

$path = '';
if(!empty($opt['path'])){
$path .= $opt['path'];

if(!is_dir($path)){
mkdir($path, 0777, true);
}
} else {
$path .= './download';
}

foreach ($nLinks as $nLink) {

$destination = $path;

$other_path = $this->permalink($this->info($nLink, 'filename')).'.'.$this->info($nLink, 'extension');

if(!is_dir($destination)){
mkdir($destination, 0777, true);
}

if(file_exists($destination.'/'.$other_path)){

$remote_file = $this->remoteFileSize($nLink);
$local_file = filesize($destination.'/'.$other_path);

if($remote_file != $local_file){
unlink($destination.'/'.$other_path);
copy($nLink, $destination.'/'.$other_path);
$sources = (isset($sources)) ? (!is_array($sources) ? [$sources] : $sources) : null;
if(!is_null($sources)){
foreach ($sources as $source) {
$new_file_name = $this->info($source, 'filename');
$new_file_extension = $this->info($source, 'extension');
$new_file = $this->permalink($new_file_name).'.'.$new_file_extension;

if(!is_null($destinations)){
foreach ($destinations as $destination) {
$new_file_path = $destination.'/'.$new_file;

if(copy($source, $new_file_path)){
$result[] = $new_file_path;
}
}
}
} else {
copy($nLink, $destination.'/'.$other_path);
}

$result[] = $destination.'/'.$other_path;
}
}

return $result;

}

/**
Expand Down

0 comments on commit 2129944

Please sign in to comment.