定制 mikehaertl/php-tmpfile 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mikehaertl/php-tmpfile

最新稳定版本:1.3.0

Composer 安装命令:

composer require mikehaertl/php-tmpfile

包简介

A convenience class for temporary files

关键字:

README 文档

README

GitHub Tests Packagist Version Packagist Downloads GitHub license

A convenience class for temporary files.

Features

  • Create temporary file with arbitrary content
  • Delete file after use (can be disabled)
  • Send file to client, either inline or with save dialog, optionally with custom HTTP headers
  • Save file locally

Examples

<?php
use mikehaertl\tmp\File;

$file = new File('some content', '.html');

// send to client for download
$file->send('home.html');
// ... with custom content type (autodetected otherwhise)
$file->send('home.html', 'application/pdf');
// ... for inline display (download dialog otherwhise)
$file->send('home.html', 'application/pdf', true);
// ... with custom headers
$file->send('home.html', 'application/pdf', true, [
    'X-Header' => 'Example',
]);

// save to disk
$file->saveAs('/dir/test.html');

// Access file name and directory
echo $file->getFileName();
echo $file->getTempDir();

If you want to keep the temporary file, e.g. for debugging, you can set the $delete property to false:

<?php
use mikehaertl\tmp\File;

$file = new File('some content', '.html');
$file->delete = false;

Default HTTP headers can also be added:

<?php
use mikehaertl\tmp\File;

File::$defaultHeader['X-Header'] = 'My Default';

$file = new File('some content', '.html');
$file->send('home.html');

The $ignoreUserAbort option (on by default) mitigates an issue where the file was not deleted if the user closes the connection during a download. Try setting it to false if you experience unexpected behavior.

统计信息

  • 总下载量: 27.67M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 100
  • 点击次数: 1
  • 依赖项目数: 25
  • 推荐数: 0

GitHub 信息

  • Stars: 95
  • Watchers: 1
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04