#笔记(三十七)#PHP伪协议小结

本文全面解析了URI Scheme,包括file、http、ftp、php、data、glob、phar、ssh2、rar、ogg和expect等协议的用法。深入介绍了如何通过不同的协议访问本地文件、网络资源、输入输出流、压缩文件、音频流以及处理交互式流。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官方文档
大佬总结

file://— 访问本地文件系统
  • 用法(file:// [文件的绝对路径和文件名])
    • /path/to/file.ext
    • relative/path/to/file.ext
    • fileInCwd.ext
    • C:/path/to/winfile.ext
    • C:\path\to\winfile.ext
    • \smbserver\share\path\to\winfile.ext
    • file:///path/to/file.ext
http://— 访问 HTTP(s) 网址
  • 允许通过 HTTP 1.0 的 GET方法,以只读访问文件或资源
  • 数据流允许读取资源的 body,而 headers 则储存在了 $http_response_header 变量里
  • 如果需要知道文档资源来自哪个 URL, 需要处理数据流返回的系列响应报头(response headers)
  • 用法
    • http://example.com
    • http://example.com/file.php?var1=val1&var2=val2
    • http://user:password@example.com
    • https://example.com
    • https://example.com/file.php?var1=val1&var2=val2
    • https://user:password@example.com
  • stream_get_meta_data
    • 从封装协议文件指针中取得报头/元数据
ftp:// — 访问 FTP(s) URLs
  • 允许通过 FTP 读取存在的文件,以及创建新文件
  • 用法
    • ftp://example.com/pub/file.txt
    • ftp://user:password@example.com/pub/file.txt
    • ftps://example.com/pub/file.txt
    • ftps://user:password@example.com/pub/file.txt
php://— 访问各个输入/输出流(I/O streams)
  • php://stdin, php://stdout 和 php://stderr
    • 允许直接访问 PHP 进程相应的输入或者输出流
    • 如果你打开 php://stdin 并在之后关了它, 仅是关闭了复制品,真正被引用的 STDIN 并不受影响
  • php://input
    • 访问请求的原始数据的只读流
  • php://fd
    • 允许直接访问指定的文件描述符
  • php://memory 和 php://temp
    • 允许读写临时数据
    • php://temp 的内存限制可通过添加 /maxmemory:NN 来控 制,NN 是以字节为单位、保留在内存的最大数据量,超过则使用临时文件。
  • php://filter
    • 复合链接
    • php://filter/resource=<待过滤的数据流>
    • php://filter/read=<读链需要应用的过滤器列表>
    • php://filter/write=<写链需要应用的过滤器列表>
zlib:// — 压缩流
  • 和phar://一样用于读取压缩文件,不过对于"zip://test.zip#file.txt"中的"#“要编码为”%23".因为url的#后的内容不会被传送
  • zip://archive.zip#dir/file.txt
  • zip:// [压缩文件绝对路径]#[压缩文件内的子文件名]
data:// — 数据(RFC 2397)
  • data://text/plain;base64,
glob:// — 查找匹配的文件路径模式
  • glob://
phar:// — PHP 归档
ssh2:// — Secure Shell 2
  • 用法
    • ssh2.shell://user:pass@example.com:22/xterm
    • ssh2.exec://user:pass@example.com:22/usr/local/bin/somecmd
    • ssh2.tunnel://user:pass@example.com:22/192.168.0.1:14
    • ssh2.sftp://user:pass@example.com:22/path/to/filename
rar:// — RAR
  • rar://<url encoded archive name>[*][#[<url encoded entry name>]]
ogg:// — 音频流
  • ogg://soundfile.ogg
  • ogg:///path/to/soundfile.ogg
  • ogg://http://www.example.com/path/to/soundstream.ogg
expect:// — 处理交互式的流
  • expect://command
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值