109 lines
3.2 KiB
PHP
109 lines
3.2 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
|
|
set_time_limit(0);
|
|
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
$dirPath = $_SERVER['DOCUMENT_ROOT']."/upload/reqs";
|
|
|
|
$token = SelectelApi::getNewToken();
|
|
|
|
for($num = 0; $num <= 3000000; $num++) {
|
|
|
|
$tempDir = $dirPath . "/" . $num;
|
|
|
|
if (is_dir($tempDir)) {
|
|
copyFiles($tempDir, $token);
|
|
}
|
|
}
|
|
|
|
function copyFiles($dirPath, $token) {
|
|
if (!is_dir($dirPath)) {
|
|
throw new InvalidArgumentException("$dirPath must be a directory");
|
|
}
|
|
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
|
|
$dirPath .= '/';
|
|
}
|
|
$files = glob($dirPath . '*', GLOB_MARK);
|
|
|
|
foreach ($files as $file) {
|
|
if (is_dir($file)) {
|
|
copyFiles($file, $token);
|
|
} else {
|
|
$url = str_replace("/var/www/sites/joywork.ru/prod", "https://uf.joywork.ru", $file);
|
|
|
|
echo "check url " . $url . "<br/>";
|
|
|
|
$res = doesFileUrlExists($url);
|
|
|
|
if ($res[0]) {
|
|
|
|
echo "file exists <br/>";
|
|
} else {
|
|
echo "file NOT exists <br/>";
|
|
|
|
$extension = pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
$contType = "application/octet-stream";
|
|
|
|
if ($extension) {
|
|
$extension = strtolower($extension);
|
|
}
|
|
|
|
if ($extension === "doc") {
|
|
$contType = "application/msword";
|
|
}
|
|
if ($extension === "html") {
|
|
$contType = "text/html";
|
|
}
|
|
if ($extension === "docx") {
|
|
$contType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
}
|
|
if ($extension === "xls") {
|
|
$contType = "application/vnd.ms-excel";
|
|
}
|
|
if ($extension === "xlsx") {
|
|
$contType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
}
|
|
if ($extension === "pdf") {
|
|
$contType = "application/pdf";
|
|
}
|
|
if ($extension === "jpeg" || $extension === "jpg") {
|
|
$contType = "image/jpeg";
|
|
}
|
|
if ($extension === "gif") {
|
|
$contType = "image/gif";
|
|
}
|
|
if ($extension === "png") {
|
|
$contType = "image/png";
|
|
}
|
|
if ($extension === "mp3") {
|
|
$contType = "audio/mpeg";
|
|
}
|
|
if ($extension === "zip") {
|
|
$contType = "application/zip";
|
|
}
|
|
if ($extension === "rar") {
|
|
$contType = "application/vnd.rar";
|
|
}
|
|
|
|
$new_path = str_replace("https://uf.joywork.ru", "", $url);
|
|
|
|
echo $contType . "<br/>";
|
|
echo $new_path . "<br/>";
|
|
|
|
SelectelApi::uploadUserFile($token, $file, $new_path, $contType);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function doesFileUrlExists($url) {
|
|
$headers = get_headers($url, true);
|
|
return [(stripos($headers[0], "200 OK") ? true : false), (isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0)];
|
|
}
|
|
|
|
|