1

I am getting the above error when trying to run the following lines of script:

$fileInfo = new SplFileInfo($subfile);
if ($fileInfo->getExtension() == 'brd') {
    $debug->alert_code_info($fileInfo);
    $filesize = $fileInfo->getSize();
    functionName($subfile, 'application/octet-stream', $filesize);
}

The getExtension function works, as I'm able to proceed to the code within the if block. So why is getExtension() working while getSize() isn't?

Eric LaRue
  • 57
  • 1
  • 10
  • How can we possibly tell you, if we can't see the SplFileInfo class with the `getSize()` method? – icecub Jun 14 '17 at 23:31
  • Here you go: http://php.net/manual/en/class.splfileinfo.php – Eric LaRue Jun 14 '17 at 23:33
  • Seems to have something to do with the size of the file you're processing. Seems that if the file is larger than what's set in your php.ini file under `post_max_size` and `upload_max_filesize`, it'll pop up this exception. – icecub Jun 14 '17 at 23:40
  • Something simular was asked here: https://stackoverflow.com/questions/24138189/runtimeexception-splfileinfogetsize-stat-failed-for-laravel-4-upload-ima Although it's Lavarel, the problem is essentialy the same. – icecub Jun 14 '17 at 23:44
  • @icecub That's only relevant if the OP is working on uploaded files (which might be the case, but we don't know). OP.. are you working on uploaded files? – M. Eriksson Jun 14 '17 at 23:48
  • @MagnusEriksson Agreed. Though after doing some research on Google, it seems that's the only (known) case where this perticular exception pops up. That's why I mentioned it like that. – icecub Jun 14 '17 at 23:52
  • If you mean do I use a form to upload files, the answer is no. This is part of an automated script that searches through a file directory and finds files meeting certain criteria (that's the $subfile) and then copying them to another folder. Although I suppose if this fits the definition of "upload," then yes, I am. – Eric LaRue Jun 14 '17 at 23:59
  • 1
    No, that's not file upload so the above ini-settings shouldn't matter. Make sure that you pass an absolute file path to `SplFileInfo()` (like `/full/path/from/the/root/myfile.brd`). You will get that error if you're trying to stat a file that's not found. – M. Eriksson Jun 15 '17 at 00:07
  • @MagnusEriksson You're right. On php.net it stated that it returns false if the file isn't found. But when I tested it on my server it indeed returns the exception and not simply false – icecub Jun 15 '17 at 00:10
  • @icecub Don't know where you saw that it returns false? This is from the [manual for SplFileInfo](http://php.net/manual/en/splfileinfo.getsize.php): _"A RuntimeException will be thrown if the file does not exist or an error occurs."_ – M. Eriksson Jun 15 '17 at 00:14
  • @MagnusEriksson In the comments of [SplFileInfo:getSize](http://php.net/manual/en/splfileinfo.getsize.php) – icecub Jun 15 '17 at 00:15
  • @MagnusEriksson But ye, my mistake. I shouldn't have relied on the comments. So I stand corrected :) – icecub Jun 15 '17 at 00:18
  • If it's that the file isn't found, shouldn't it be that getExtension() should throw an exception as well? It seems to be finding the file, just not finding the size of the file. – Eric LaRue Jun 15 '17 at 16:48

0 Answers0