fopen
laravel/framework
Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Opens file or URL
fopen
(
string $filename
,
string $mode
,
bool $use_include_path
=
false
,
?
resource $context
=
null
):
resource
|
false
{
$contents
=
''
;
$handle
=
fopen
(
$path
,
'rb'
);
if (
$handle
) {
try {
src/Illuminate/Filesystem/Filesystem.php
public function
putFileAs
(
$path
,
$file
,
$name
,
$options
= [])
{
$stream
=
fopen
(
is_string
(
$file
) ?
$file
:
$file
->
getRealPath
(),
'r'
);
src/Illuminate/Filesystem/FilesystemAdapter.php
protected function
createResource
(
$path
,
$mode
)
{
$this
->
handle
= @
fopen
(
$path
,
$mode
);
if (!
$this
->
handle
) {
throw new
Exception
(
'Unable to create lockable file: '
.
$path
.
'. Please ensure you have permission to create files in this location.'
);
src/Illuminate/Filesystem/LockableFile.php
file_put_contents
(
$this
->
tempDir
.
'/foo.txt'
,
'some-data'
);
$filesystemAdapter
= new
FilesystemAdapter
(
$this
->
filesystem
,
$this
->
adapter
);
$stream
=
fopen
(
$this
->
tempDir
.
'/foo.txt'
,
'r'
);
$guzzleStream
= new
Stream
(
$stream
);
$filesystemAdapter
->
put
(
'bar.txt'
,
$guzzleStream
);
fclose
(
$stream
);
tests/Filesystem/FilesystemAdapterTest.php
{
$this
->
factory
->
fakeSequence
()->
push
(
'abc123'
);
$resource
=
fopen
(
'php://temp'
,
'w'
);
$this
->
factory
->
sink
(
$resource
)->
get
(
'https://example.com'
);
tests/Http/HttpClientTest.php
'foo.com/*'
=> [
'page'
=>
'foo'
],
]);
$resource
=
fopen
(
'php://temp'
,
'w'
);
$this
->
factory
->
sink
(
$resource
)->
get
(
'http://foo.com/test'
);
tests/Http/HttpClientTest.php