当前位置:网站首页>PHP OSS file reads and writes files, and workman generates temporary files and outputs them to the browser for download
PHP OSS file reads and writes files, and workman generates temporary files and outputs them to the browser for download
2022-06-24 19:20:00 【owenzhang24】

- fstat function : Show all the information about the file
- File read : fread($fp,filesize($file_path));
- write file :file_put_contents($file_path,$con,FILE_APPEND);
- Application of file operation : Can operate ini file . Write the configuration of the server in ini In file , And then operate it .
- Copy files :copy("e:\2.txt","d:\1.txt")
- Create folder :mkdir($path,0777,true)
// Read the file header("Content-Type: text/html;charset=utf-8"); // Set character encoding $file = base\_path() . "/public/index.m3u8"; $read = fopen($file, 'r'); $contents = fread($read, filesize($file)); $string1 = getBeforeString($contents, 'enc.key'); $string2 = getLaterString($contents, 'enc.key'); $newContents = $string1 . 'enc.key?token=123' . $string2; fclose($read); // write file 、 $file = base\_path() . "/public/test22.m3u8"; $handle = fopen($file, 'w'); // Open file fwrite($handle, $newContents); // Write content fclose($handle); // Close file readfile($file); // Read and output all the contents of the file return redirect(WEB\_URL . '/test22.m3u8');// Transfer page // Read OSS file $file = OSS\_URL . $url1; // Add the contents of the file to the array $fileContent = @file($file); $newContent = ''; // Traverse every line of the file foreach ($fileContent as $value) { // Whether this character exists on this line of the file , With this replacement if (strpos($value, 'api.qingsong.chaotuapp.com/') !== false) { $value = str\_replace('app.com/', "q.com/ckey", $value); } // Whether this character exists on this line of the file , There is this splicing content if (strpos($value, '.ts') !== false) { $value = $ossUrl . $value; } $newContent .= $value; }// write file $fileName = "$token.m3u8"; // ./59ee8147cf3f42575bc91ff586d54837.m3u8 $file = "./$fileName"; // Open file $handle = fopen($file, 'w'); // Write content fwrite($handle, $newContent); // Convert file to string $content = file\_get\_contents($file); // Delete temporary files unlink($file); // Output browser $response = new Response(); return $response->withHeader('content-description', 'File Transfer') ->withHeader('content-type', 'application/force-download') ->withHeader('content-disposition', "attachment; filename={$fileName}") ->withHeader('content-transfer-encoding', 'binary') ->withHeader('pragma', 'public') ->withBody($content);
Buy me a cup of coffee :)
Think it will help you , Just give me a reward , thank you !
Wechat appreciation code link , Click the jump :
https://www.owenzhang.com/wechat_reward.png
边栏推荐
- 网络安全审查办公室对知网启动网络安全审查
- Using to release resources
- PingCAP 入选 2022 Gartner 云数据库“客户之声”,获评“卓越表现者”最高分
- thinkphp6中怎么使用jwt认证
- Nokov motion capture system makes it possible for multi field cooperative UAV to build independently
- 使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
- ls 常用参数
- Make track map
- Server lease error in Hong Kong may lead to serious consequences
- Interprétation de la thèse (SR - gnn) Shift Robust GNNS: Overcoming the Limits of Localized Graph Training Data
猜你喜欢

Set up your own website (8)

一次 MySQL 误操作导致的事故,高可用都不顶不住!

西北工业大学遭黑客攻击?双因素认证改变局面!

Air pollution gas satellite data download tutorial

Understanding openstack network

Volcano devient l'ordonnanceur de lots par défaut Spark

System design idea of time traceability

php OSS文件读取和写入文件,workerman生成临时文件并输出浏览器下载

建立自己的网站(8)

制造业项目MDM主数据项目实施心得
随机推荐
我链接mysql 报这个错 是啥意思呀?
Introduction to smart contract security audit delegatecall (2)
What do I mean when I link Mysql to report this error?
Why is nodejs so fast?
Introduction and download of nine npp\gpp datasets
【计算讲谈社】第三讲:如何提出关键问题?
Will the CDC read out of order when I use SQL
Necessary fault handling system for enterprise network administrator
[leetcode] rotation series (array, matrix, linked list, function, string)
R language 4.1.0 software installation package and installation tutorial
ArrayList源码解析
Introduction and tutorial of SAS planet software
【Leetcode】旋转系列(数组、矩阵、链表、函数、字符串)
R语言 4.1.0软件安装包和安装教程
Experience of MDM master data project implementation for manufacturing projects
微信小程序轮播图怎么自定义光标位置
three. Basic framework created by JS
Self taught C special data type
Freeswitch使用originate转dialplan
60 个神级 VS Code 插件!!