当前位置:网站首页>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
边栏推荐
- Learn routing and data delivery
- Several ways of connecting upper computer and MES
- starring开发HttpJson接入点+数据库
- NOKOV动作捕捉系统使多场协同无人机自主建造成为可能
- ls 常用参数
- 使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
- 想问下 pgsql cdc 账号同一个 多个 task 会有影响吗,我现在3个task 只有一个 有
- Sentry series satellite introduction and download tutorial
- 应用程序DDoS攻击原理及防御方法
- Starring V6 platform development take out point process
猜你喜欢
Introduction and tutorial of SAS planet software
High dimension low code: component rendering sub component
API管理之利剑 -- Eolink
解读HarmonyOS 应用与服务生态
Introduction and download tutorial of administrative division vector data
php OSS文件读取和写入文件,workerman生成临时文件并输出浏览器下载
为什么生命科学企业都在陆续上云?
ArrayList源码解析
starring V6平台开发接出点流程
「碎语杂记」这事儿不安全
随机推荐
thinkphp6中怎么使用jwt认证
ArrayList源码解析
Using to release resources
Generate the last login user account report of the computer through SCCM SQL
Freeswitch uses origin to dialplan
Tkde2022: Dialogue recommendation system based on knowledge enhanced sampling
多云模式并非“万能钥匙”
subject may not be empty [subject-empty]
Introduction and download of nine npp\gpp datasets
物联网?快来看 Arduino 上云啦
finkcdc支持sqlserver2008么?
This is not safe
Development of NFT dual currency pledge liquidity mining system
使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
通过SCCM SQL生成计算机上一次登录用户账户报告
The sharp sword of API management -- eolink
Volcano成Spark默认batch调度器
Understanding openstack network
解读HarmonyOS 应用与服务生态
网络安全审查办公室对知网启动网络安全审查