【发布时间】:2020-04-13 21:04:37
【问题描述】:
我在我的站点根目录 (example.com/file.php) 中创建了一个 php 文件:
$head = array_change_key_case(get_headers("https://example.com/somefile.zip", TRUE));
$filesize = $head['content-length'];
echo $filesize;
当我运行文件时,我得到以下输出:1234173 它以千字节为单位返回文件大小。 我还在我的 WordPress 主题(example.com/wp-content/themes/my_theme/single.php)中使用完全相同的代码,但输出始终为 0。
为什么? (我使用此代码获取下载框中文件的大小)
使用 curl 时,我得到了相同的结果。 (curl 在我的根目录中是可以的,但它在 wp 中没有 content-length 参数)
【问题讨论】:
标签: php wordpress curl get-headers