是否可以使用PHP将文件移出localhost?

时间:2018-08-01 16:14:05

标签: php file directory zip structure

我意识到我业务中的每个客户都有相同的文件夹/文件结构,所以我制作了一个文件夹/文件模板,而不是使用在我的本地主机上运行的PHP脚本创建自己的所有文件夹/文件,该模板,并在以客户端命名的文件夹中复制文件夹/文件,此处为代码:

$clientName = "RosaBazbaz";
$tmpPath = __DIR__ . "/tmp";
$templatesPath = __DIR__ . "/templates";
$absoluteZIPPath = join("/", [$tmpPath, $clientName]) . ".zip";

//Creates ZIP file containing all folder/files structure in template
$zip = new ZipArchive();

if($zip->open($absoluteZIPPath,  ZIPARCHIVE::OVERWRITE | ZIPARCHIVE::CREATE)) {

$source = realpath(join("/", [$templatesPath, "lunasMiel"]));

if(is_dir($source)) {

    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);

    foreach($files as $file) {

        $file = realpath($file);

        if(is_dir($file)) {

            $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));

        } else if(is_file($file)) {

            $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
        }
    }

} else if(is_file($source)) {

    $zip->addFromString(basename($source), file_get_contents($source));
}
}

$zip->close();

//Extracts Generated ZIP
$zip = new ZipArchive;
if($zip->open($absoluteZIPPath) != "true") {

    echo "Error :- Unable to open the Zip File";
}

$zip->extractTo(str_replace(".zip", "", $absoluteZIPPath));
$zip->close();

//Deletes Zip File
unlink($absoluteZIPPath);

我的问题是:我需要在我的Google云端硬盘中保存这些文件夹,以便我备份它们并与同事共享,那么是否有可能使脚本将它们移到我的本地主机之外?

0 个答案:

没有答案