略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: stream_is_local

2024-11-13

stream_is_local

(PHP 5 >= 5.2.4, PHP 7, PHP 8)

stream_is_localChecks if a stream is a local stream

说明

stream_is_local(resource|string $stream): bool

Checks if a stream, or a URL, is a local one or not.

参数

stream

The stream resource or URL to check.

返回值

成功时返回 true, 或者在失败时返回 false

范例

示例 #1 stream_is_local() example

Basic usage example.

<?php
var_dump
(stream_is_local("http://example.com"));
var_dump(stream_is_local("/etc"));
?>

以上例程的输出类似于:

bool(false)
bool(true)
add a noteadd a note

User Contributed Notes 5 notes

up
1
Anonymous
5 years ago
this is not a bug
mounting a remote filesystem locally "imports" it so it is available to userland programs like a local directory.
up
1
Gemorroj
4 years ago
but hhvm for `file://shouldbelocal.jpg` returns true
https://3v4l.org/ULCni
up
1
php at kalpaitch dot com
5 years ago
It appears to return incorrectly for 'file://' wrapper which I would consider to be local.

CODE:
$file1 = '/somefile.jpg';
$file2 = 'file://shouldbelocal.jpg';
$file3 = 'http://someotherfile.jpg';

$local = stream_is_local($file1);
$shouldbelocal = stream_is_local($file2);
$remote = stream_is_local($file3);
var_dump($local, $shouldbelocal, $remote);

RESULT:
bool(true)
bool(false)
bool(false)
up
1
nryabov
7 months ago
<?php
$file1
= '/somefile.jpg';
$file2 = 'file://shouldbelocal.jpg';
$file3 = 'http://someotherfile.jpg';
$file4 = 'file:///indeedlocal.jpg'; // Please note '///' instead of '//'

$local = stream_is_local($file1);
$shouldbelocal = stream_is_local($file2);
$remote = stream_is_local($file3);
$indeedlocal = stream_is_local($file4);
var_dump($local, $shouldbelocal, $remote, $indeedlocal);
up
-1
sam at NOSPAM dot bogus dot tld
5 years ago
The function stream_is_local() does not work with remote mounts points, like sshfs mount points (it will return true as if it was local).

官方地址:https://www.php.net/manual/en/function.stream-is-local.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3