81 lines
2.0 KiB
PHP
81 lines
2.0 KiB
PHP
<?php
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
|
|
ini_set('error_reporting', E_ALL);
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
|
|
function read_dir($main_path){
|
|
global $arrPath;
|
|
global $arrFile;
|
|
if ($handle = opendir($main_path)) { // открыт текущий каталог
|
|
|
|
while (false !== ($file = readdir($handle))) {
|
|
|
|
if ($file != "." && $file != "..")
|
|
{
|
|
$temp_path = $main_path."/".$file;
|
|
//echo $temp_path."\n\n";
|
|
if(is_dir($temp_path)){
|
|
read_dir($temp_path);
|
|
} else if(is_file($temp_path)){
|
|
if(isset(explode('.', $file)[1]) && explode('.', $file)[1] == "mp3"){
|
|
if(!in_array($main_path, $arrPath)){
|
|
$arrPath[] = $main_path;
|
|
}
|
|
$arrFile[] = $temp_path;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
closedir($handle);
|
|
}
|
|
//return $path;
|
|
}
|
|
|
|
//чтение каталога
|
|
$main_path = $_SERVER['DOCUMENT_ROOT']."/server";
|
|
$arrPath = array();
|
|
$arrFile = array();
|
|
read_dir($main_path);
|
|
|
|
$result = SelectelApi::getTokenAndUrl();
|
|
|
|
$token = $result[0];
|
|
$storageUrl = $result[1];
|
|
|
|
foreach ($arrFile as $file){
|
|
|
|
$partFile = str_replace($main_path.'/','',$file);
|
|
$arrPath = explode("/", $partFile);
|
|
$arrPathParts = array();
|
|
$fileName = '';
|
|
foreach ($arrPath as $key => $path){
|
|
if($key == (count($arrPath)-1)){
|
|
$fileName = $path;
|
|
} else {
|
|
$arrPathParts[] = $path;
|
|
}
|
|
}
|
|
|
|
if(!empty($fileName)){
|
|
$ftpPath = '';
|
|
foreach ($arrPathParts as $patch){
|
|
$ftpPath .= "/$patch";
|
|
}
|
|
$selectelPath = $ftpPath.'/'.$fileName;
|
|
|
|
$r = SelectelApi::uploadMp3File($storageUrl, $token, $file, $selectelPath);
|
|
|
|
if ($r) {
|
|
echo "скопирован в $selectelPath \n";
|
|
unlink($file);
|
|
} else {
|
|
echo "не скопирован в $selectelPath \n";
|
|
}
|
|
}
|
|
}
|
|
?>
|