main Zip

zip main
 avatar
alceawisteria
php
a year ago
2.3 kB
5
Indexable
<!--<a target=_blank href="alceawis.de.zip">(dld)</a><br>-->
<?php
$phpVersion = phpversion();
echo "PHP version: " . $phpVersion;
?>(must be PHP version: 8.2.20 !)<br>

<?php
$delfile = 'alceawis.de.zip';
if (file_exists($delfile)) {
    $fileModifiedTime = filemtime($delfile);
    $currentTime = time();
    $fifteenMinutesAgo = $currentTime - (15 * 60);
    if ($fileModifiedTime < $fifteenMinutesAgo) {
        unlink($delfile);
        echo "File deleted successfully.<br>";
    } else {
        echo "File is not older than 15 minutes.<br>";
    }
} else {
    echo "File does not exist.<br>";
}
?>


<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $zip = new ZipArchive();
    $zipFileName = __DIR__ . '/alceawis.de.zip';
    $intermediateFolderName = pathinfo($zipFileName, PATHINFO_FILENAME);

    if ($zip->open($zipFileName, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator('.', RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::LEAVES_ONLY
        );

        foreach ($files as $name => $file) {
            if (!$file->isDir()) {
                $filePath = $file->getRealPath();
                $relativePath = $intermediateFolderName . '/' . substr($filePath, strlen(__DIR__) + 1);
                $zip->addFile($filePath, $relativePath);
            }
        }

        $zip->close();
         //$downloadLink = '<a target=_blank href="' . $zipFileName . '">Click here to download</a>';
         //$downloadLink = '<a target=_blank href="alceawis.de.zip">Click here to download the zip file</a>';
         $downloadLink = '<a target=_blank href="alceawis.de.zip?v=' . time() . '">Click here to download the zip file</a>';
        echo 'Files zipped successfully. ' . $downloadLink;
    } else {
        echo 'Failed to create zip file.';
    }
}
?>

<form method="POST">
    <button type="submit">Zip Files</button>
</form>

<!---delete-->
<?php
$file = 'alceawis.de.zip';
if (isset($_GET['delete'])) {
    if (file_exists($file)) {
        unlink($file);
        echo "File deleted successfully.";
    } else {
        echo "File not found.";
    }
}
?>
<a href="?delete=true">Click here to delete zip</a>

Editor is loading...
Leave a Comment