-1

此代码正在执行压缩和下载完美但我想更改日期我该怎么做

当我保存一个文件夹时,它的保存时间我想保存日期我该怎么做

这是时间脚本当我更改 Ymd 时如何更改为最新,但这不起作用它显示此错误解析错误:语法错误,第 26 行的 downloadlist.php 中的意外 T_STRING

请帮我解决这个问题

谢谢

$filename = Y-m-d " Backup.zip"; (not working)

$filename =  time() ." Backup.zip"; ( working code)

下载列表.php

<?php
        // function download($file) downloads file provided in $file
        function download($file) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename='.basename($file));
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            ob_clean();
            flush();
            readfile($file);
            exit;
        }

        $files = $_POST['file'];
        if(empty($files)) 
        {
            echo("You haven't selected any file to download.");
        } 
        else 
        {
            $zip = new ZipArchive();
            $filename =  time() ." Backup.zip"; //adds timestamp to zip archive so every file has unique filename
            if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { // creates new zip archive
                    exit("Cannot open <$filename>\n");
            }
            $N = count($files);
            for($i=0; $i < $N; $i++)
            {
              $zip->addFile($files[$i], $files[$i]); //add files to archive
            }
            $numFiles = $zip->numFiles;
            $zip->close();

            $time = 8; //how long in seconds do we wait for files to be archived.
            $found = false;
            for($i=0; $i<$time; $i++){

             if($numFiles == $N){   // check if number of files in zip archive equals number of checked files
                download($filename);
                $found = true;
                break;
             }
             sleep(1); // if not found wait one second before continue looping
         }

         if($found) { }
             else echo "Sorry, this is taking too long";
         }
    ?>

列表.php

<?php

function listDir($dirName) 
{  
    $forbidden_files=array('.htaccess','.htpasswd');

    $allow_ext=array('.pdf','.doc','.docx','.xls','.xlsx','.txt');
    ?><form name="filelist" action="downloadList.php" method="POST"><?php echo "\n";
    if ($handle = opendir($dirName)) {
        while (false !== ($file = readdir($handle))     ) {
            $allowed=(strpos($file,'.')!==false  &&  in_array(substr($file,strpos($file,'.')) ,$allow_ext ));

           if ($file != "." && $file != ".."  && $allowed ) { ?>    <input type=checkbox name="file[]" value="<?php  echo "$file";?>"><?php  echo "$file"; ?><br><?php  echo "\n";
            }
        }
    closedir($handle);
    }
    ?><br><input type="submit" name="formSubmit" value="Zip and download" /></form><?php
}
listDir('.');  ?>
4

1 回答 1

-1

$filename = Ymd "Backup.zip"; (不工作)

因为你没有date()在这里使用。此外,您没有使用..

$filename = date('Y-m-d')."Backup.zip";

上面的代码将为您工作。

于 2013-11-04T05:00:17.860 回答