相关疑难解决方法(0)

PHP:如何检查图像文件是否存在?

我需要查看我的cdn上是否存在特定图像.

我尝试过以下内容并不起作用:

if (file_exists(http://www.example.com/images/$filename)) {
    echo "The file exists";
} else {
    echo "The file does not exist";
}
Run Code Online (Sandbox Code Playgroud)

即使图像存在或不存在,它总是说"文件存在".我不确定为什么它不起作用......

php file-io image file

93
推荐指数
8
解决办法
26万
查看次数

如何仅包含文件存在

我需要一个include只包含文件的函数/语句.PHP中有一个吗?

您可能建议使用@include但该方法存在问题 - 如果要包含的文件存在,如果解析器在包含的文件中发现错误,PHP将不会输出警告.

php

39
推荐指数
3
解决办法
4万
查看次数

is_file/file_exists性能和缓存

我做了一些测试来比较和测量两种功能的速度.is_file似乎比file_exists快几倍(我使用10000次迭代).我想知道PHP或OS是否为这些功能使用了一些缓存,或者是否始终访问HDD?我想不,但我想知道......

我用过这段代码:

<?php
$time = microtime();
$time = explode(' ', $time);
$begintime = $time[1] + $time[0];
for($i=0;$i<10000;$i++)
    file_exists('/Applications/MAMP/htdocs/index.php');
$time = microtime();
$time = explode(" ", $time);
$endtime = $time[1] + $time[0];
$totaltime = ($endtime - $begintime);
echo 'PHP parsed this in ' .$totaltime. ' seconds.</br>';
$time = microtime();
$time = explode(" ", $time);
$begintime = $time[1] + $time[0];
for($i=0;$i<10000;$i++)
    is_file('/Applications/MAMP/htdocs/index.php');
$time = microtime();
$time = explode(" ", $time);
$endtime = $time[1] + $time[0];
$totaltime = ($endtime …
Run Code Online (Sandbox Code Playgroud)

php performance

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

php ×3

file ×1

file-io ×1

image ×1

performance ×1