1分钟部署网站📞AI智能客服,大模型训练自有数据,简单好用,有效降低客服成本 广告
data://协议必须双在on才能正常使用; * allow\_url\_fopen :on * allow\_url\_include:on **封装协议摘要** | 属性 | 支持 | | --- | --- | | 受限于[allow\_url\_fopen](https://www.php.net/manual/zh/filesystem.configuration.php#ini.allow-url-fopen) | No | | 受限于[allow\_url\_include](https://www.php.net/manual/zh/filesystem.configuration.php#ini.allow-url-include) | Yes | | 允许读取 | Yes | | 允许写入 | No | | 允许追加 | No | | 允许同时读写 | No | | 支持[stat()](https://www.php.net/manual/zh/function.stat.php) | No | | 支持[unlink()](https://www.php.net/manual/zh/function.unlink.php) | No | | 支持[rename()](https://www.php.net/manual/zh/function.rename.php) | No | | 支持[mkdir()](https://www.php.net/manual/zh/function.mkdir.php) | No | | 支持[rmdir()](https://www.php.net/manual/zh/function.rmdir.php) | No | ``` http://127.0.0.1/code/1.php?file=data://text/plain,<?php phpinfo()?> http://127.0.0.1/code/1.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpPz4= ``` ![](https://img.kancloud.cn/ce/d4/ced4c03d787701e49fc6c199ce1a670f_1004x220.png) ![](https://img.kancloud.cn/64/d9/64d98207863b6ad483f97006d6124cf5_949x271.png) 获取媒体类型 ``` $fp = fopen('data://text/plain;base64,', 'r'); $meta = stream_get_meta_data($fp); // 打印 "text/plain" echo $meta['mediatype']; ``` 不要直接传输原数据,特别是在数据中存在+时,因为PHP会自动对传递的字符串中的所有实体进行urldecode,+在此步骤时丢失我么需要urlencode()或者base64\_encode()转码在传输 ``` $data='Günther says: 1+1 is 2, 10%40 is 20.'; $fp = fopen('data:text/plain,'.urlencode($data), 'rb'); // urlencoded data echostream_get_contents($fp); $fp = fopen('data:text/plain;base64,'.base64_encode($data), 'rb'); // base64 encoded data echostream_get_contents($fp); ```