相关疑难解决方法(0)

php创建拉链没有路径到zip文件的路径

我正在尝试使用php创建一个zip文件(它可以从这个页面中获取 - http://davidwalsh.name/create-zip-php),但是在zip文件中是所有的文件夹名称.文件本身.

是否可以让zip文件中的文件减去所有文件夹?

这是我的代码:

function create_zip($files = array(), $destination = '', $overwrite = true) {

    if(file_exists($destination) && !$overwrite) { return false; };
    $valid_files = array();
    if(is_array($files)) {
        foreach($files as $file) { 
            if(file_exists($file)) { 
                $valid_files[] = $file;
            };
        };
    };
    if(count($valid_files)) { 
        $zip = new ZipArchive();
        if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { 
            return false;
        };
        foreach($valid_files as $file) { 
            $zip->addFile($file,$file);
        };
        $zip->close();
        return file_exists($destination);
    } else {
        return false;
    };

};


$files_to_zip = array('/media/138/file_01.jpg','/media/138/file_01.jpg','/media/138/file_01.jpg');

$result = create_zip($files_to_zip,'/...full_site_path.../downloads/138/138_files.zip');
Run Code Online (Sandbox Code Playgroud)

php directory zip

48
推荐指数
2
解决办法
4万
查看次数

使多个文件强制下载

对不起,如果标题没有解释.让我试着进一步解释.

我的代码看起来像这样:

<?
//Grab the number in count.txt
$count = intval(file_get_contents('count.txt'));
//Move the number up one
file_put_contents('count.txt', ++$count);
$number = file_get_contents('count.txt');
//Force Download
header('Content-Disposition: attachment; filename=DataFiles'.$number.".csv");
header('Content-Type: application/octet-stream');

//The data

foreach($array as $info){
echo $info."\n";
}
?>
Run Code Online (Sandbox Code Playgroud)

$ array是一个数组.

现在有时数据量可能超过5000,因此如果数据超过5000,则为每个回显的5000个数据创建另一个文件.Ea:如果$ array中有20,000个数据,那么它将总共生成4个文件.

php arrays header

8
推荐指数
3
解决办法
4万
查看次数

从php循环创建多个csv文件

我试图创建一个循环,在执行时它会创建多个 csv 文件并下载它们。这是我的代码:

session_start();
require '../connect.php'; //connect.php has connection info for my database
// and uses the variable $connect

$sqldept     = "SELECT department_name from department;";
$departments = mysqli_query($connect, $sqldept);

while ($department = mysqli_fetch_array($departments)) {
    $department = $department[0];
    header('Content-Type: text/csv; charset=utf-8');
    header("Content-Transfer-Encoding: UTF-8");
    header('Content-Disposition: attachment; filename=summary-' . $department . '.csv');
    header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
    header("Pragma: no-cache"); // HTTP 1.0
    header("Expires: 0"); // Proxies

    $date  = date("Y-m-d", strtotime("-28 days" . date("Y-m-d")));
    $edate = date("Y-m-d");

    $startdate  = "(time.dateadded BETWEEN '$date' …
Run Code Online (Sandbox Code Playgroud)

php csv loops

6
推荐指数
1
解决办法
6570
查看次数

使用php下载多个文件作为zip文件夹

我想让我的用户选择列出的任何类型的文件,并将它们作为zip文件夹下载并下载.文件可能是.doc,.jpeg,.ppt等

php zip

5
推荐指数
1
解决办法
1万
查看次数

PHP Zip 文件下载打开时出错

我需要从网站下载 zip 文件,因为我需要在一次下载中合并多个文件(最多 100 个单独的文件)

尝试创建 zip 文件时,它会按预期下载,文件名也按预期以“YYYY.MM.DD - HH.MM.SS”格式显示。尝试在 Windows 7 (或 winzip)中打开 zip 文件时出现问题- 我收到以下错误消息。这种情况在多次尝试中反复发生。

我假设我在编码创建或下载 zip 文件时犯了一个错误,而不是 zip 文件格式本身是一个问题,因为我可以打开不同的 zip 文件 - 谁能看到我可能犯的错误?(错误图像下方包含代码)

我尝试使用php作为参考来下载多个文件作为 zip 文件。

//backup file name based on current date and time
$filename = date("Y.m.j - H.i.s");
//name of zip file used when downloading
$zipname = 'temp.zip';
//create new zip file
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
//yes, I know the zip file is empty …
Run Code Online (Sandbox Code Playgroud)

php zip file download

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×5

zip ×3

arrays ×1

csv ×1

directory ×1

download ×1

file ×1

header ×1

loops ×1