当前位置:网站首页>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
边栏推荐
- 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
- subject may not be empty [subject-empty]
- subject may not be empty [subject-empty]
- Using to release resources
- Knowledge points in T-SQL
- Introduction to smart contract security audit delegatecall (2)
- Value passing and reference passing of value types and reference types in CSharp
- Use ado Net call stored procedure
- Huawei machine learning service speech recognition function enables applications to paint "sound" and color
猜你喜欢
Volcano becomes spark default batch scheduler
Air pollution gas satellite data download tutorial
Interpreting harmonyos application and service ecology
Volcano成Spark默認batch調度器
Introduction and download tutorial of administrative division vector data
Spatial simulation model acquisition future land cover tutorial
Starring V6 platform development take out point process
Volcano devient l'ordonnanceur de lots par défaut Spark
Introduction and download tutorial of two types of soil data
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
随机推荐
Do you have all the basic embedded knowledge points that novices often ignore?
建立自己的网站(8)
In depth learning of movement methods
The cdc+mysql connector joins the date and time field from the dimension table by +8:00. Could you tell me which one is hosted by Alibaba cloud
Generate the last login user account report of the computer through SCCM SQL
C self learning function
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
Tkde2022: Dialogue recommendation system based on knowledge enhanced sampling
「碎语杂记」这事儿不安全
Multi segment curve temperature control FB (SCL program) of PLC function block series
Starring V6 platform development take out point process
The script implements the automated deployment of raid0
上位机与MES对接的几种方式
three.js创建的基础框架
60 个神级 VS Code 插件!!
电源噪声分析
Knowledge points in T-SQL
Using to release resources
Introduction and download tutorial of two types of soil data
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