当前位置:网站首页>php OSS文件讀取和寫入文件,workerman生成臨時文件並輸出瀏覽器下載
php OSS文件讀取和寫入文件,workerman生成臨時文件並輸出瀏覽器下載
2022-06-24 19:19: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
边栏推荐
- 西北工业大学遭黑客攻击?双因素认证改变局面!
- starring V6平台开发接出点流程
- 我用sql形式的会出现cdc读取乱序吗
- Starring develops httpjson access point + Database
- MySQL basic commands
- This is not safe
- High dimension low code: component rendering sub component
- Buddha bless you that there will never be a bug
- 一次 MySQL 误操作导致的事故,高可用都不顶不住!
- Introduction and download tutorial of two types of soil data
猜你喜欢

干货 | 新手经常忽略的嵌入式基础知识点,你都掌握了吗?

Volcano成Spark默认batch调度器

Do you have all the basic embedded knowledge points that novices often ignore?

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

Interprétation de la thèse (SR - gnn) Shift Robust GNNS: Overcoming the Limits of Localized Graph Training Data

建立自己的网站(8)

Why are life science enterprises on the cloud in succession?

Understanding openstack network

Network security review office starts network security review on HowNet

three.js创建的基础框架
随机推荐
电源噪声分析
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
Remote sensing Forum
60 个神级 VS Code 插件!!
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
干货 | 新手经常忽略的嵌入式基础知识点,你都掌握了吗?
Dataworks development ODPs SQL development production environment automatic completion of ProjectName
Introduction to alos satellite
Several ways of connecting upper computer and MES
Using alicloud RDS for SQL Server Performance insight to optimize database load - first understanding of performance insight
BSS应用程序云原生部署的8大挑战
Volcano devient l'ordonnanceur de lots par défaut Spark
Unity移动端游戏性能优化简谱之 以引擎模块为划分的CPU耗时调优
[computer talk club] Lecture 3: how to raise key issues?
What do I mean when I link Mysql to report this error?
Introduction and download tutorial of two types of soil data
Starring V6 platform development take out point process
怎么使用R包ggtreeExtra绘制进化树
智能合约安全审计入门篇 —— delegatecall (2)
flink cdc全量读mysql老是报这个错怎么处理