当前位置:网站首页>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
边栏推荐
- subject may not be empty [subject-empty]
- 小滴课堂海量数据处理商用短链平台大课
- Spatial simulation model acquisition future land cover tutorial
- Introduction to smart contract security audit delegatecall (2)
- 论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
- The script implements the automated deployment of raid0
- 物联网?快来看 Arduino 上云啦
- 佛祖保佑 永无BUG
- Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
- BSS应用程序云原生部署的8大挑战
猜你喜欢

Module V

Intel and Microsoft give full play to the potential energy of edge cloud collaboration to promote the large-scale deployment of AI

建立自己的网站(8)

论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》

60 个神级 VS Code 插件!!

Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data

High dimension low code: component rendering sub component

Introduction and download of nine npp\gpp datasets

Volcano becomes spark default batch scheduler

How to use R package ggtreeextra to draw evolution tree
随机推荐
Module V
制造业项目MDM主数据项目实施心得
Huawei machine learning service speech recognition function enables applications to paint "sound" and color
Introduction and download tutorial of two types of soil data
Introduction and download of nine npp\gpp datasets
Starring V6 platform development take out point process
Would you like to ask whether the same multiple tasks of the PgSQL CDC account will have an impact? I now have only one of the three tasks
网络安全审查办公室对知网启动网络安全审查
Necessary fault handling system for enterprise network administrator
假如,程序员面试的时候说真话
AI时代生物隐私如何保护?马德里自治大学最新《生物特征识别中的隐私增强技术》综述,全面详述生物隐私增强技术
小白请教下各位大佬,cdc抽取mysql binlog是严格顺序的吗
为什么生命科学企业都在陆续上云?
ArrayList源码解析
多云模式并非“万能钥匙”
System design idea of time traceability
Freeswitch uses origin to dialplan
使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
想问下 pgsql cdc 账号同一个 多个 task 会有影响吗,我现在3个task 只有一个 有
Sentry series satellite introduction and download tutorial