当前位置:网站首页>php OSS文件读取和写入文件,workerman生成临时文件并输出浏览器下载
php OSS文件读取和写入文件,workerman生成临时文件并输出浏览器下载
2022-06-24 18:50:00 【owenzhang24】

- fstat函数:显示文件的所有信息
- 文件读取: fread($fp,filesize($file_path));
- 写入文件:file_put_contents($file_path,$con,FILE_APPEND);
- 文件操作的应用:可以操作ini文件。将服务器的配置写在ini文件中,再对其进行操作。
- 拷贝文件:copy("e:\2.txt","d:\1.txt")
- 创建文件夹:mkdir($path,0777,true)
//读取文件 header("Content-Type: text/html;charset=utf-8"); //设置字符编码 $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); //写入文件、 $file = base\_path() . "/public/test22.m3u8"; $handle = fopen($file, 'w'); //打开文件 fwrite($handle, $newContents); //写入内容 fclose($handle); //关闭文件 readfile($file); //读取并输出文件全部内容 return redirect(WEB\_URL . '/test22.m3u8');//调转页面//读取OSS文件 $file = OSS\_URL . $url1; //文件内容加入数组 $fileContent = @file($file); $newContent = ''; //遍历文件的每一行 foreach ($fileContent as $value) { //文件该行是否存在这个字符,有这替换内容 if (strpos($value, 'api.qingsong.chaotuapp.com/') !== false) { $value = str\_replace('app.com/', "q.com/ckey", $value); } //文件该行是否存在这个字符,有这拼接内容 if (strpos($value, '.ts') !== false) { $value = $ossUrl . $value; } $newContent .= $value; }//写入文件 $fileName = "$token.m3u8"; // ./59ee8147cf3f42575bc91ff586d54837.m3u8 $file = "./$fileName"; //打开文件 $handle = fopen($file, 'w'); //写入内容 fwrite($handle, $newContent); //将文件转字符串 $content = file\_get\_contents($file); //删除临时文件 unlink($file); //输出浏览器 $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 :)
觉得对你有帮助,就给我打赏吧,谢谢!
微信赞赏码链接,点击跳转:
https://www.owenzhang.com/wechat_reward.png
边栏推荐
- 请教一个问题。adbhi支持保留一个ID最新100条数据库,类似这样的操作吗
- Real time rendering: the difference between real-time, offline, cloud rendering and hybrid rendering
- Solve the problem that the MapReduce program console does not have log information warn please initialize the log4j system properly
- 1: Mosaic of 100W basic geographic information data
- Experience of MDM master data project implementation for manufacturing projects
- Why is nodejs so fast?
- 干货 | 新手经常忽略的嵌入式基础知识点,你都掌握了吗?
- 怎么使用R包ggtreeExtra绘制进化树
- Ask a question. Adbhi supports the retention of 100 databases with the latest IDs. Is this an operation like this
- Introduction, download and use of global meteorological data CRU ts from 1901 to 2020
猜你喜欢
随机推荐
Experience of MDM master data project implementation for manufacturing projects
How to perform power regression in R
Microservice system design -- interface document management design
小滴课堂海量数据处理商用短链平台大课
Northwestern Polytechnic University attacked by hackers? Two factor authentication changes the situation!
西北工业大学遭黑客攻击?双因素认证改变局面!
At present, only CDC monitors Mysql to get the data of new columns. Sqlserver can't, can it
High dimension low code: component rendering sub component
Make track map
应用程序DDoS攻击原理及防御方法
Interpreting harmonyos application and service ecology
The script implements the automated deployment of raid0
Will the CDC read out of order when I use SQL
ls 常用参数
R language 4.1.0 software installation package and installation tutorial
特尔携手微软发挥边云协同势能,推动AI规模化部署
cdc+mysql connector从维表中join的日期时间字段会被+8:00,请问阿里云托管的
Fabric ledger data block structure analysis (I): how to analyze the smart contract transaction data in the ledger
What type of datetime in the CDC SQL table should be replaced
「碎语杂记」这事儿不安全

![[leetcode] rotation series (array, matrix, linked list, function, string)](/img/9e/079311df16fa8e28708f4e050e531f.png)







