当前位置:网站首页>PHP OSS file reads and writes files, and workman generates temporary files and outputs them to the browser for download
PHP OSS file reads and writes files, and workman generates temporary files and outputs them to the browser for download
2022-06-24 19:20:00 【owenzhang24】

- fstat function : Show all the information about the file
- File read : fread($fp,filesize($file_path));
- write file :file_put_contents($file_path,$con,FILE_APPEND);
- Application of file operation : Can operate ini file . Write the configuration of the server in ini In file , And then operate it .
- Copy files :copy("e:\2.txt","d:\1.txt")
- Create folder :mkdir($path,0777,true)
// Read the file header("Content-Type: text/html;charset=utf-8"); // Set character encoding $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); // write file 、 $file = base\_path() . "/public/test22.m3u8"; $handle = fopen($file, 'w'); // Open file fwrite($handle, $newContents); // Write content fclose($handle); // Close file readfile($file); // Read and output all the contents of the file return redirect(WEB\_URL . '/test22.m3u8');// Transfer page // Read OSS file $file = OSS\_URL . $url1; // Add the contents of the file to the array $fileContent = @file($file); $newContent = ''; // Traverse every line of the file foreach ($fileContent as $value) { // Whether this character exists on this line of the file , With this replacement if (strpos($value, 'api.qingsong.chaotuapp.com/') !== false) { $value = str\_replace('app.com/', "q.com/ckey", $value); } // Whether this character exists on this line of the file , There is this splicing content if (strpos($value, '.ts') !== false) { $value = $ossUrl . $value; } $newContent .= $value; }// write file $fileName = "$token.m3u8"; // ./59ee8147cf3f42575bc91ff586d54837.m3u8 $file = "./$fileName"; // Open file $handle = fopen($file, 'w'); // Write content fwrite($handle, $newContent); // Convert file to string $content = file\_get\_contents($file); // Delete temporary files unlink($file); // Output browser $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 :)
Think it will help you , Just give me a reward , thank you !
Wechat appreciation code link , Click the jump :
https://www.owenzhang.com/wechat_reward.png
边栏推荐
猜你喜欢

「碎语杂记」这事儿不安全

程序员大部分时间不是写代码,而是。。。

Multi cloud mode is not a "master key"

FROM_ GLC introduction and data download tutorial
![subject may not be empty [subject-empty]](/img/6b/9b57a7ed3ab086036cb6dfe0b31de4.png)
subject may not be empty [subject-empty]

Necessary fault handling system for enterprise network administrator
![[leetcode] rotation series (array, matrix, linked list, function, string)](/img/9e/079311df16fa8e28708f4e050e531f.png)
[leetcode] rotation series (array, matrix, linked list, function, string)

LabView之MQTT协议使用

R language 4.1.0 software installation package and installation tutorial

Make track map
随机推荐
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
工作6年,月薪3W,1名PM的奋斗史
cdc+mysql connector从维表中join的日期时间字段会被+8:00,请问阿里云托管的
Application DDoS attack principle and defense method
模块五
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
In depth learning of movement methods
MySQL binlog data source configuration document, please share
Buddha bless you that there will never be a bug
Application scenarios of channel of go question bank · 11
R语言corrplot相关热图美化实例分析
Introduction and download of nine npp\gpp datasets
解读HarmonyOS 应用与服务生态
Northwestern Polytechnic University attacked by hackers? Two factor authentication changes the situation!
Volcano becomes spark default batch scheduler
Understanding openstack network
Microsoft planetary computer (MPC) platform introduction, registration and comparison
Experience of MDM master data project implementation for manufacturing projects
High dimension low code: component rendering sub component
How to select the ECS type and what to consider?