In PHP, after assigning a file pointer resource to a variable using the fopen () function, how can I get the file name from a variable?

For instance:

$file = fopen("File.txt", "r");
$filename = $file->basename;

if there is a method like basename for file objects (file pointer resources).

+3
source share
3 answers

No , the method does not exist. You must save the file name in a variable, for example:

<?php
$filename = "File.txt";
$file = fopen($filename, "r");
$basename = basename($filename);

, : , , , var_dump() ( - resource(3) of type (stream)). , , PHP PHP . , fread(), fwrite() fclose().

+3

, .

, ?

+5

, , PHP tmpfile() - . , Unix. tempnam(realpath(sys_get_temp_dir()), "piclib_");.

+4

Source: https://habr.com/ru/post/1762734/


All Articles