当前位置: 首页>>代码示例>>PHP>>正文


PHP ZipArchive::addfile方法代码示例

本文整理汇总了PHP中ZipArchive::addfile方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::addfile方法的具体用法?PHP ZipArchive::addfile怎么用?PHP ZipArchive::addfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZipArchive的用法示例。


在下文中一共展示了ZipArchive::addfile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sqlbackup

function sqlbackup($ip, $sql, $username, $password)
{
    global $meurl;
    if (class_exists('ZipArchive')) {
        maintop("MySQL备份");
        $database = $sql;
        //数据库名
        $options = array('hostname' => $ip, 'charset' => 'utf8', 'filename' => $database . '.sql', 'username' => $username, 'password' => $password);
        mysql_connect($options['hostname'], $options['username'], $options['password']) or die("不能连接数据库!");
        mysql_select_db($database) or die("数据库名称错误!");
        mysql_query("SET NAMES '{$options['charset']}'");
        $tables = list_tables($database);
        $filename = sprintf($options['filename'], $database);
        $fp = fopen($filename, 'w');
        foreach ($tables as $table) {
            dump_table($table, $fp);
        }
        fclose($fp);
        //压缩sql文件
        if (file_exists('mysql.zip')) {
            unlink('mysql.zip');
        }
        $file_name = $options['filename'];
        $zip = new ZipArchive();
        $res = $zip->open('mysql.zip', ZipArchive::CREATE);
        if ($res === TRUE) {
            $zip->addfile($file_name);
            $zip->close();
            //删除服务器上的sql文件
            unlink($file_name);
            echo '<div class="box">数据库导出并压缩完成!' . " <a href=\"" . $meurl . "?op=home&folder=" . $_SESSION['folder'] . "\">返回上次浏览的文件夹</a></div>\n";
        } else {
            printerror('无法压缩文件!');
        }
        exit;
        mainbottom();
    } else {
        printerror('此服务器上的PHP不支持ZipArchive,无法压缩文件!');
    }
}
开发者ID:HY-ZHQ,项目名称:daocloud,代码行数:40,代码来源:webftp.php

示例2: mkdir

    /**
     * Menu export render
     * @return void
     */
    function submenu_export()
    {
        global $wpdb;
        if (!is_dir(plugin_dir_path(__FILE__) . '../tmp')) {
            mkdir(plugin_dir_path(__FILE__) . '../tmp');
            chmod(plugin_dir_path(__FILE__) . '../tmp', 0747);
        }
        $destination = plugin_dir_path(__FILE__) . '../tmp/export_visual_chat.zip';
        $zip = new ZipArchive();
        if (file_exists($destination)) {
            unlink($destination);
        }
        if ($zip->open($destination, ZipArchive::CREATE) !== true) {
            return false;
        }
        $jsonExport = array();
        $table_name = $wpdb->prefix . "vcht_settings";
        $settings = $wpdb->get_results("SELECT * FROM {$table_name} WHERE id=1 LIMIT 1");
        $jsonExport['settings'] = $settings;
        $table_name = $wpdb->prefix . "vcht_logs";
        $steps = array();
        foreach ($wpdb->get_results("SELECT * FROM {$table_name}") as $key => $row) {
            $steps[] = $row;
        }
        $jsonExport['logs'] = $steps;
        $table_name = $wpdb->prefix . "vcht_messages";
        $items = array();
        foreach ($wpdb->get_results("SELECT * FROM {$table_name}") as $key => $row) {
            $items[] = $row;
        }
        $jsonExport['messages'] = $items;
        $table_name = $wpdb->prefix . "vcht_texts";
        $items = array();
        foreach ($wpdb->get_results("SELECT * FROM {$table_name}") as $key => $row) {
            $items[] = $row;
        }
        $jsonExport['texts'] = $items;
        $fp = fopen(plugin_dir_path(__FILE__) . '../tmp/export_visual_chat.json', 'w');
        fwrite($fp, json_encode($jsonExport));
        fclose($fp);
        $zip->addfile(plugin_dir_path(__FILE__) . '../tmp/export_visual_chat.json', 'export_visual_chat.json');
        $zip->close();
        ?>
        <div class="wrap wpeExport">
            <h2>Export data</h2>
            <p>
                Export all this plugin datas to a zip file will can be imported on another website.
            </p>
            <p>
                <a download class="button-primary" href="<?php 
        echo esc_url(trailingslashit(plugins_url('/', $this->parent->file))) . 'tmp/export_visual_chat.zip';
        ?>
">Export</a>
            </p>
        </div>
        <?php 
    }
开发者ID:JDjimenezdelgado,项目名称:old-mmexperience,代码行数:61,代码来源:vcht_admin_menu.php

示例3: ZipArchive

 }
 //CRIA E ABRE ARQUIVO ZIP QUE SERÁ ENVIADO POR E-MAIL PARA O RESPONSÁVEL (OU ENVIADO PARA FTP DE FORMA OPCIONAL - VIDE CÓDIGO COMENTADO MAIS ABAIXO)
 $zip = new ZipArchive();
 $criou = $zip->open($caminhoServidor . "/{$EventoSemAcent}/certificados.zip", ZipArchive::CREATE);
 //CABEÇALHO DO E-MAIL (ALTERAR CAMPOS FROM E RETURN-PATH COM OS SEUS VALORES)
 $headers = "MIME-Version: 1.1\r\n";
 $headers .= "Content-type: text/plain; charset=utf-8\r\n";
 $headers .= "From: SEU-EMAIL <seu@email.br>\r\n";
 // remetente
 $headers .= "Return-Path: seu@email.br\r\n";
 // return-path
 //GERA CERTIFICADO PARA CADA NOME FORNECIDO, INSERE NO ARQUIVO ZIP, ENVIA POR E-MAIL PARA O ALUNO E INSERE NO BANCO DE DADOS
 for ($i = 0; $i < $qtd_nomes; $i++) {
     geraCertificado($Data, $NomeAluno[$i], $Evento, $orador, $CargaHoraria, $organizadorEvento, $caminhoServidor);
     $NomeAlunoSemAcent = remove_acentuacao($NomeAluno[$i], true);
     $zip->addfile($caminhoServidor . "/{$EventoSemAcent}/" . $NomeAlunoSemAcent . ".pdf", $NomeAlunoSemAcent . ".pdf");
     $hash = md5($NomeAlunoSemAcent . $Evento);
     $data = date("y-m-d H:i:s");
     //ENVIA EMAIL, SE INFORMADO
     if (isset($EmailAluno) && $EmailAluno[$i] != "") {
         $msg = "Olá {$NomeAluno[$i]},\n\t\t\t\t\n\nSeu certificado está disponível no link abaixo.\n\t\t\t\t\n\nDownload do Certificado: {$downloadURL}/{$EventoSemAcent}/{$NomeAlunoSemAcent}.pdf\n\t\t\t\t\n\nPara verificar a veracidade dos certificados, acesse o link: {$downloadURL}\n\t\t\t\t\n\nObrigado pela sua participação!";
         mail($EmailAluno[$i], "Certificado - {$Evento}", $msg, $headers);
         $emailAluno = $EmailAluno[$i];
     } else {
         $emailAluno = "";
     }
     $sql = "INSERT INTO certificado (evento,organizador_evento,nome_participante,email_participante,hash_validacao,data) \n\t\t\t\t\t\tVALUES ('" . utf8_decode($Evento) . "','" . utf8_decode($organizadorEvento) . "','" . utf8_decode($NomeAluno[$i]) . "','" . $emailAluno . "','{$hash}','{$data}')";
     $conn->query($sql);
 }
 $zip->close();
 /**
开发者ID:viniciuscl,项目名称:gerador-certificados,代码行数:31,代码来源:certificado.php

示例4: sqlbackup

function sqlbackup($ip, $sql, $username, $password)
{
    global $meurl;
    if (class_exists('ZipArchive')) {
        maintop("MySQL Backup");
        $database = $sql;
        $options = array('hostname' => $ip, 'charset' => 'utf8', 'filename' => $database . '.sql', 'username' => $username, 'password' => $password);
        mysql_connect($options['hostname'], $options['username'], $options['password']) or die("Fail to connect DB!");
        mysql_select_db($database) or die("Database name error!");
        mysql_query("SET NAMES '{$options['charset']}'");
        $tables = list_tables($database);
        $filename = sprintf($options['filename'], $database);
        $fp = fopen($filename, 'w');
        foreach ($tables as $table) {
            dump_table($table, $fp);
        }
        fclose($fp);
        if (file_exists('mysql.zip')) {
            unlink('mysql.zip');
        }
        $file_name = $options['filename'];
        $zip = new ZipArchive();
        $res = $zip->open('mysql.zip', ZipArchive::CREATE);
        if ($res === TRUE) {
            $zip->addfile($file_name);
            $zip->close();
            unlink($file_name);
            echo 'Database Export and compression jobs done!' . " <a href=\"" . $meurl . "?op=root&folder=" . $_SESSION['folder'] . "\">Back</a>\n";
        } else {
            printerror('Unable to compress files!');
        }
        exit;
        mainbottom();
    } else {
        printerror('PHP on this server does not support ZipArchive, unable to extract the zip files!');
    }
}
开发者ID:ZhiweiHwang,项目名称:SimpleFileServer,代码行数:37,代码来源:SimpleFileServer.php


注:本文中的ZipArchive::addfile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。