-1

I'm reading data from a file and need to run checks on its extension

I opened the file handle with fopen and given the handle to pathinfo()

$handle2 = fopen('files/ppGM.txt', 'r');
$fileinfo = pathinfo($handle2);

I need the array of informations from path info but the functions requires the first parameter to be string:

Warning: pathinfo() expects parameter 1 to be string, resource given in /home/kroman02/public_www/p1tma/index.php on line 21

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Yrok Kory
  • 17
  • 3

1 Answers1

1

pathinfo() as it suggests - works with the path of a file and not a file handle. So you would usually use something like...

$fileName = 'files/ppGM.txt';
$handle2 = fopen($fileName, 'r');
$fileinfo = pathinfo($fileName);

and this would result with $fileinfo containing...

Array
(
    [dirname] => files
    [basename] => ppGM.txt
    [extension] => txt
    [filename] => ppGM
)
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55