作者 梁鹏山

服务器与git建立通信

正在显示 328 个修改的文件 包含 753 行增加2 行删除
<?php
return [
'Item_id' => '项目id',
'Images' => '图片',
'Details' => '详情',
'Is_sift' => '是否为精选',
'Is_sift 0' => '否',
'Is_sift 1' => '是',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
'Item.title' => '名称'
];
... ...
<?php
return [
'Item_id' => '项目id',
'Images' => '图片',
'Details' => '详情',
'Is_sift' => '是否为精选',
'Is_sift 0' => '否',
'Is_sift 1' => '是',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
'Item.title' => '名称'
];
... ...
<?php
return [
'Campus_id' => '校区id',
'Ronda_id' => '场次id',
'Item_id' => '项目id',
'Createtime' => '创建时间',
'Updatetime' => '更新时间'
];
... ...
<?php
namespace app\admin\validate\item;
use think\Validate;
class Details extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
/**
* 定时任务
* @ApiWeigh (94)
*/
class Crontab extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (首页)
*/
public function index(){
$res = db('study')->field('earn_score')->select();
function sort($res){
$len = count($res);
for ($i = 0; $i < $len - 1; $i++) {//循环比对的轮数
for ($j = 0; $j < $len - $i - 1; $j++) {//当前轮相邻元素循环对比
if ($res[$j] < $res[$j + 1]) {//如果前边的小于后边的
$tmp = $res[$j];//交换数据
$res[$j] = $res[$j + 1];
$res[$j + 1] = $tmp;
}
}
}
return $res;
}
$this->success('',sort($res));
}
}
\ No newline at end of file
... ...
... ... @@ -41,5 +41,5 @@ return array (
'category2' => 'Category2',
'custom' => 'Custom',
),
'privacy_policy' => '<p><img src="http://campus.cn/uploads/20230307/e7ab2a28f4cb819fd6536ce7381583a9.png"/></p><p>用户:在手机、平板电脑、电脑等注册成为平台(以下简称“平台”或“平台方”)的使用者,通过平台发布、查看、接收图文/音频/视频信息或其他文件,或与其他用户进行延时/实时交流的用户(以下简称“用户”)。</p>',
'privacy_policy' => '<p><img src="http://rramxwmk1.hb-bkt.clouddn.com/uploads/20230310/e7ab2a28f4cb819fd6536ce7381583a9.png"/></p><p>用户:在手机、平板电脑、电脑等注册成为平台(以下简称“平台”或“平台方”)的使用者,通过平台发布、查看、接收图文/音频/视频信息或其他文件,或与其他用户进行延时/实时交流的用户(以下简称“用户”)。</p>',
);
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// [ 后台入口文件 ]
// 使用此文件可以达到隐藏admin模块的效果
// 为了你的安全,强烈不建议将此文件名修改成admin.php
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
// 判断是否安装
if (!is_file(APP_PATH . 'admin/command/Install/install.lock')) {
header("location:./install.php");
exit;
}
// 加载框架引导文件
require __DIR__ . '/../thinkphp/base.php';
// 绑定到admin模块
\think\Route::bind('admin');
// 关闭路由
\think\App::route(false);
// 设置根url
\think\Url::root('');
// 执行应用
\think\App::run()->send();
... ...
... ... @@ -9,7 +9,7 @@
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
define('THINK_VERSION', '5.0.24');
define('THINK_VERSION', '5.0.25');
define('THINK_START_TIME', microtime(true));
define('THINK_START_MEM', memory_get_usage());
define('EXT', '.php');
... ...
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpdocumentor" version="^3.3.1" installed="3.3.1" location="./tools/phpdocumentor" copy="false"/>
</phive>
... ...
<?php
declare(strict_types=1);
/**
* PHP-CS-Fixer config for ZipStream-PHP
* @author Nicolas CARPi <nico-git@deltablot.email>
* @copyright 2022 Nicolas CARPi
* @see https://github.com/maennchen/ZipStream-PHP
* @license MIT
* @package maennchen/ZipStream-PHP
*/
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$finder = Finder::create()
->exclude('.github')
->exclude('.phpdoc')
->exclude('docs')
->exclude('tools')
->exclude('vendor')
->in(__DIR__);
$config = new Config();
return $config->setRules([
'@PER' => true,
'@PER:risky' => true,
'@PHP81Migration' => true,
'@PHPUnit84Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'class_attributes_separation' => true,
'declare_strict_types' => true,
'dir_constant' => true,
'is_null' => true,
'no_homoglyph_names' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'non_printable_character' => true,
'ordered_imports' => true,
'ordered_class_elements' => true,
'php_unit_construct' => true,
'pow_to_exponentiation' => true,
'psr_autoloading' => true,
'random_api_migration' => true,
'return_assignment' => true,
'self_accessor' => true,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_line_comment_style' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'strict_param' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_functions' => true,
'import_constants' => true,
],
])
->setFinder($finder)
->setRiskyAllowed(true);
\ No newline at end of file
... ...
{% extends 'layout.html.twig' %}
{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "https://maennchen.dev/ZipStream-PHP/guide/index.html"},
{ "name": "API", "url": "https://maennchen.dev/ZipStream-PHP/classes/ZipStream-ZipStream.html"},
{ "name": "Issues", "url": "https://github.com/maennchen/ZipStream-PHP/issues"},
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/maennchen/ZipStream-PHP"},
{ "iconClass": "fas fa-envelope-open-text", "url": "https://github.com/maennchen/ZipStream-PHP/discussions"},
{ "iconClass": "fas fa-money-bill", "url": "https://opencollective.com/zipstream"},
]
}
%}
\ No newline at end of file
... ...
Adding Content-Length header
=============
Adding a ``Content-Length`` header for ``ZipStream`` is not trivial since the
size is not known beforehand.
The following workaround adds an approximated header:
.. code-block:: php
class Zip
{
/** @var string */
private $name;
private $files = [];
public function __construct($name)
{
$this->name = $name;
}
public function addFile($name, $data)
{
$this->files[] = ['type' => 'addFile', 'name' => $name, 'data' => $data];
}
public function addFileFromPath($name, $path)
{
$this->files[] = ['type' => 'addFileFromPath', 'name' => $name, 'path' => $path];
}
public function getEstimate()
{
$estimate = 22;
foreach ($this->files as $file) {
$estimate += 76 + 2 * strlen($file['name']);
if ($file['type'] === 'addFile') {
$estimate += strlen($file['data']);
}
if ($file['type'] === 'addFileFromPath') {
$estimate += filesize($file['path']);
}
}
return $estimate;
}
public function finish()
{
header('Content-Length: ' . $this->getEstimate());
$options = new \ZipStream\Option\Archive();
$options->setSendHttpHeaders(true);
$options->setEnableZip64(false);
$options->setDeflateLevel(-1);
$zip = new \ZipStream\ZipStream($this->name, $options);
$fileOptions = new \ZipStream\Option\File();
$fileOptions->setMethod(\ZipStream\Option\Method::STORE());
foreach ($this->files as $file) {
if ($file['type'] === 'addFile') {
$zip->addFile($file['name'], $file['data'], $fileOptions);
}
if ($file['type'] === 'addFileFromPath') {
$zip->addFileFromPath($file['name'], $file['path'], $fileOptions);
}
}
$zip->finish();
exit;
}
}
It only works with the following constraints:
- All file content is known beforehand.
- Content Deflation is disabled
Thanks to
`partiellkorrekt <https://github.com/maennchen/ZipStream-PHP/issues/89#issuecomment-1047949274>`_
for this workaround.
\ No newline at end of file
... ...
Usage with FlySystem
===============
For saving or uploading the generated zip, you can use the
`Flysystem <https://flysystem.thephpleague.com>`_ package, and its many
adapters.
For that you will need to provide another stream than the ``php://output``
default one, and pass it to Flysystem ``putStream`` method.
.. code-block:: php
// Open Stream only once for read and write since it's a memory stream and
// the content is lost when closing the stream / opening another one
$tempStream = fopen('php://memory', 'w+');
// Init Options
$zipStreamOptions = new Archive();
$zipStreamOptions->setOutputStream($tempStream);
// Create Zip Archive
$zipStream = new ZipStream('test.zip', $zipStreamOptions);
$zipStream->addFile('test.txt', 'text');
$zipStream->finish();
// Store File (see Flysystem documentation, and all its framework integration)
$adapter = new Local(__DIR__.'/path/to/folder'); // Can be any adapter (AWS, Google, Ftp, etc.)
$filesystem = new Filesystem($adapter);
$filesystem->putStream('test.zip', $tempStream)
// Close Stream
fclose($tempStream);
\ No newline at end of file
... ...
Usage with nginx
=============
If you are using nginx as a webserver, it will try to buffer the response.
So you'll want to disable this with a custom header:
.. code-block:: php
header('X-Accel-Buffering: no');
# or with the Response class from Symfony
$response->headers->set('X-Accel-Buffering', 'no');
Alternatively, you can tweak the
`fastcgi cache parameters <https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_buffers>`_
within nginx config.
See `original issue <https://github.com/maennchen/ZipStream-PHP/issues/77>`_.
\ No newline at end of file
... ...
Available options
===============
Here is the full list of options available to you. You can also have a look at
``src/Option/Archive.php`` file.
First, an instance of ``ZipStream\Option\Archive`` needs to be created, and
after that you use setters methods to modify the values.
.. code-block:: php
use ZipStream\ZipStream;
use ZipStream\Option\Archive as ArchiveOptions;
require_once 'vendor/autoload.php';
$opt = new ArchiveOptions();
// Define output stream (argument is of type resource)
$opt->setOutputStream($fd);
// Set the deflate level (default is 6; use -1 to disable it)
$opt->setDeflateLevel(6);
// Add a comment to the zip file
$opt->setComment('This is a comment.');
// Size, in bytes, of the largest file to try and load into memory (used by addFileFromPath()). Large files may also be compressed differently; see the 'largeFileMethod' option.
$opt->setLargeFileSize(30000000);
// How to handle large files. Legal values are STORE (the default), or DEFLATE. Store sends the file raw and is significantly faster, while DEFLATE compresses the file and is much, much slower. Note that deflate must compress the file twice and is extremely slow.
$opt->setLargeFileMethod(ZipStream\Option\Method::STORE());
$opt->setLargeFileMethod(ZipStream\Option\Method::DEFLATE());
// Send http headers (default is false)
$opt->setSendHttpHeaders(false);
// HTTP Content-Disposition. Defaults to 'attachment', where FILENAME is the specified filename. Note that this does nothing if you are not sending HTTP headers.
$opt->setContentDisposition('attachment');
// Set the content type (does nothing if you are not sending HTTP headers)
$opt->setContentType('application/x-zip');
// Set the function called for setting headers. Default is the `header()` of PHP
$opt->setHttpHeaderCallback('header');
// Enable streaming files with single read where general purpose bit 3 indicates local file header contain zero values in crc and size fields, these appear only after file contents in data descriptor block. Default is false. Set to true if your input stream is remote (used with addFileFromStream()).
$opt->setZeroHeader(false);
// Enable reading file stat for determining file size. When a 32-bit system reads file size that is over 2 GB, invalid value appears in file size due to integer overflow. Should be disabled on 32-bit systems with method addFileFromPath if any file may exceed 2 GB. In this case file will be read in blocks and correct size will be determined from content. Default is true.
$opt->setStatFiles(true);
// Enable zip64 extension, allowing very large archives (> 4Gb or file count > 64k)
// default is true
$opt->setEnableZip64(true);
// Flush output buffer after every write
// default is false
$opt->setFlushOutput(true);
// Now that everything is set you can pass the options to the ZipStream instance
$zip = new ZipStream('example.zip', $opt);
... ...
Usage with PSR 7 Streams
===============
PSR-7 streams are `standardized streams <https://www.php-fig.org/psr/psr-7/>`_.
ZipStream-PHP supports working with these streams with the function
``addFileFromPsr7Stream``.
For all parameters of the function see the API documentation.
Example
---------------
.. code-block:: php
$stream = $response->getBody();
// add a file named 'streamfile.txt' from the content of the stream
$zip->addFileFromPsr7Stream('streamfile.txt', $stream);
... ...
Stream Output
===============
Stream to S3 Bucket
---------------
.. code-block:: php
use Aws\S3\S3Client;
use Aws\Credentials\CredentialProvider;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;
$bucket = 'your bucket name';
$client = new S3Client([
'region' => 'your region',
'version' => 'latest',
'bucketName' => $bucket,
'credentials' => CredentialProvider::defaultProvider(),
]);
$client->registerStreamWrapper();
$zipFile = fopen("s3://$bucket/example.zip", 'w');
$options = new Archive();
$options->setEnableZip64(false);
$options->setOutputStream($zipFile);
$zip = new ZipStream(null, $options);
$zip->addFile('file1.txt', 'File1 data');
$zip->addFile('file2.txt', 'File2 data');
$zip->finish();
fclose($zipFile);
\ No newline at end of file
... ...
Usage with Symfony
===============
Overview for using ZipStream in Symfony
--------
Using ZipStream in Symfony requires use of Symfony's ``StreamedResponse`` when
used in controller actions.
Wrap your call to the relevant ``ZipStream`` stream method (i.e. ``addFile``,
``addFileFromPath``, ``addFileFromStream``) in Symfony's ``StreamedResponse``
function passing in any required arguments for your use case.
Using Symfony's ``StreamedResponse`` will allow Symfony to stream output from
ZipStream correctly to users' browsers and avoid a corrupted final zip landing
on the users' end.
Example for using ``ZipStream`` in a controller action to zip stream files
stored in an AWS S3 bucket by key:
.. code-block:: php
use Symfony\Component\HttpFoundation\StreamedResponse;
use Aws\S3\S3Client;
use ZipStream;
//...
/**
* @Route("/zipstream", name="zipstream")
*/
public function zipStreamAction()
{
//sample test file on s3
$s3keys = array(
"ziptestfolder/file1.txt"
);
$s3Client = $this->get('app.amazon.s3'); //s3client service
$s3Client->registerStreamWrapper(); //required
//using StreamedResponse to wrap ZipStream functionality for files on AWS s3.
$response = new StreamedResponse(function() use($s3keys, $s3Client)
{
// Define suitable options for ZipStream Archive.
$options = new \ZipStream\Option\Archive();
$options->setContentType('application/octet-stream');
// this is needed to prevent issues with truncated zip files
$options->setZeroHeader(true);
$options->setComment('test zip file.');
//initialise zipstream with output zip filename and options.
$zip = new ZipStream\ZipStream('test.zip', $options);
//loop keys - useful for multiple files
foreach ($s3keys as $key) {
// Get the file name in S3 key so we can save it to the zip
//file using the same name.
$fileName = basename($key);
//concatenate s3path.
$bucket = 'bucketname'; //replace with your bucket name or get from parameters file.
$s3path = "s3://" . $bucket . "/" . $key;
//addFileFromStream
if ($streamRead = fopen($s3path, 'r')) {
$zip->addFileFromStream($fileName, $streamRead);
} else {
die('Could not open stream for reading');
}
}
$zip->finish();
});
return $response;
}
In the above example, files on AWS S3 are being streamed from S3 to the Symfon
application via ``fopen`` call when the s3Client has ``registerStreamWrapper``
applied. This stream is then passed to ``ZipStream`` via the
``addFileFromStream`` function, which ZipStream then streams as a zip to the
client browser via Symfony's ``StreamedResponse``. No Zip is created server
side, which makes this approach a more efficient solution for streaming zips to
the client browser especially for larger files.
For the above use case you will need to have installed
`aws/aws-sdk-php-symfony <https://github.com/aws/aws-sdk-php-symfony>`_ to
support accessing S3 objects in your Symfony web application. This is not
required for locally stored files on you server you intend to stream via
``ZipStream``.
See official Symfony documentation for details on
`Symfony's StreamedResponse <https://symfony.com/doc/current/components/http_foundation.html#streaming-a-response>`_
``Symfony\Component\HttpFoundation\StreamedResponse``.
Note from `S3 documentation <https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-stream-wrapper.html>`_:
Streams opened in "r" mode only allow data to be read from the stream, and
are not seekable by default. This is so that data can be downloaded from
Amazon S3 in a truly streaming manner, where previously read bytes do not
need to be buffered into memory. If you need a stream to be seekable, you
can pass seekable into the stream context options of a function.
Make sure to configure your S3 context correctly!
Uploading a file
--------
You need to add correct permissions
(see `#120 <https://github.com/maennchen/ZipStream-PHP/issues/120>`_)
**example code**
.. code-block:: php
$path = "s3://{$adapter->getBucket()}/{$this->getArchivePath()}";
// the important bit
$outputContext = stream_context_create([
's3' => ['ACL' => 'public-read'],
]);
fopen($path, 'w', null, $outputContext);
\ No newline at end of file
... ...
Usage with Varnish
=============
Serving a big zip with varnish in between can cause random stream close.
This can be solved by adding attached code to the vcl file.
To avoid the problem, add the following to your varnish config file:
.. code-block::
sub vcl_recv {
# Varnish can’t intercept the discussion anymore
# helps for streaming big zips
if (req.url ~ "\.(tar|gz|zip|7z|exe)$") {
return (pipe);
}
}
# Varnish can’t intercept the discussion anymore
# helps for streaming big zips
sub vcl_pipe {
set bereq.http.connection = "close";
return (pipe);
}
... ...
ZipStream PHP
=============
A fast and simple streaming zip file downloader for PHP. Using this library will
save you from having to write the Zip to disk. You can directly send it to the
user, which is much faster. It can work with S3 buckets or any PSR7 Stream.
.. toctree::
index
Symfony
Options
StreamOutput
FlySystem
PSR7Streams
Nginx
Varnish
ContentLength
Installation
---------------
Simply add a dependency on ``maennchen/zipstream-php`` to your project's
``composer.json`` file if you use Composer to manage the dependencies of your
project. Use following command to add the package to your project's dependencies:
.. code-block:: sh
composer require maennchen/zipstream-php
Usage Intro
---------------
Here's a simple example:
.. code-block:: php
// Autoload the dependencies
require 'vendor/autoload.php';
// enable output of HTTP headers
$options = new ZipStream\Option\Archive();
$options->setSendHttpHeaders(true);
// create a new zipstream object
$zip = new ZipStream\ZipStream('example.zip', $options);
// create a file named 'hello.txt'
$zip->addFile('hello.txt', 'This is the contents of hello.txt');
// add a file named 'some_image.jpg' from a local file 'path/to/image.jpg'
$zip->addFileFromPath('some_image.jpg', 'path/to/image.jpg');
// add a file named 'goodbye.txt' from an open stream resource
$fp = tmpfile();
fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
rewind($fp);
$zip->addFileFromStream('goodbye.txt', $fp);
fclose($fp);
// finish the zip stream
$zip->finish();
You can also add comments, modify file timestamps, and customize (or
disable) the HTTP headers. It is also possible to specify the storage method
when adding files, the current default storage method is ``DEFLATE``
i.e files are stored with Compression mode 0x08.
Known Issues
---------------
The native Mac OS archive extraction tool prior to macOS 10.15 might not open
archives in some conditions. A workaround is to disable the Zip64 feature with
the option ``enableZip64: false``. This limits the archive to 4 Gb and 64k files
but will allow users on macOS 10.14 and below to open them without issue.
See `#116 <https://github.com/maennchen/ZipStream-PHP/issues/146>`_.
The linux ``unzip`` utility might not handle properly unicode characters.
It is recommended to extract with another tool like
`7-zip <https://www.7-zip.org/>`_.
See `#146 <https://github.com/maennchen/ZipStream-PHP/issues/146>`_.
It is the responsability of the client code to make sure that files are not
saved with the same path, as it is not possible for the library to figure it out
while streaming a zip.
See `#154 <https://github.com/maennchen/ZipStream-PHP/issues/154>`_.
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/phpDocumentor/phpDocumentor/master/data/xsd/phpdoc.xsd"
>
<title>ZipStream-PHP</title>
<paths>
<output>docs</output>
</paths>
<version number="3.0.0">
<folder>latest</folder>
<api>
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore hidden="true" symlinks="true">
<path>tests/**/*</path>
<path>vendor/**/*</path>
</ignore>
<extensions>
<extension>php</extension>
</extensions>
<visibility>public</visibility>
<default-package-name>ZipStream</default-package-name>
<include-source>true</include-source>
</api>
<guide>
<source dsn=".">
<path>guides</path>
</source>
<output>guide</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<template name="default" />
</phpdocumentor>
\ No newline at end of file
... ...
<?php
if (\PHP_VERSION_ID < 80000 && !interface_exists('Stringable')) {
interface Stringable
{
/**
* @return string
*/
public function __toString();
}
}
... ...