当前位置:网站首页>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
边栏推荐
- 特尔携手微软发挥边云协同势能,推动AI规模化部署
- BSS应用程序云原生部署的8大挑战
- Fabric ledger data block structure analysis (I): how to analyze the smart contract transaction data in the ledger
- Volcano成Spark默认batch调度器
- Set up your own website (8)
- Sentry series satellite introduction and download tutorial
- Module V
- Real time rendering: the difference between real-time, offline, cloud rendering and hybrid rendering
- 怎么使用R包ggtreeExtra绘制进化树
- PLC功能块系列之多段曲线控温FB(SCL程序)
猜你喜欢

一文详解|Go 分布式链路追踪实现原理

Multi cloud mode is not a "master key"

Starring develops httpjson access point + Database

制造业项目MDM主数据项目实施心得

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

解读HarmonyOS 应用与服务生态

Generate the last login user account report of the computer through SCCM SQL

Vite+web3: referenceerror: process is not defined

Volcano becomes spark default batch scheduler

Value passing and reference passing of value types and reference types in CSharp
随机推荐
subject may not be empty [subject-empty]
[computer talk club] Lecture 3: how to raise key issues?
C self learning function
The sharp sword of API management -- eolink
电源噪声分析
R language 4.1.0 software installation package and installation tutorial
The script implements the automated deployment of raid0
The verifiable certificate of geoscience remote sensing industry
At present, only CDC monitors Mysql to get the data of new columns. Sqlserver can't, can it
Building MVC system based on three-tier structure
Spatial simulation model acquisition future land cover tutorial
論文解讀(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
Learn routing and data delivery
Volcano becomes spark default batch scheduler
System design idea of time traceability
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
怎么使用R包ggtreeExtra绘制进化树
Volcano becomes spark default batch scheduler
Air pollution gas satellite data download tutorial
How to protect biological privacy in the AI era? Overview of the latest "privacy enhancement technology in biometrics" of the Autonomous University of Madrid, comprehensively detailing the biometric p