CodeIgniter Forums
file->move returns 1 not a file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: file->move returns 1 not a file (/showthread.php?tid=91373)



file->move returns 1 not a file - badger - 07-30-2024

ci 4.5.1. I'm using as per the docs,
PHP Code:
$file=$file->move('todir','newname',true);
   
log_message('debug',$file->getSize());

   
the file is moved correctly.
   
according to the docs and line 153 of system/files/file.php$file->move(...) returns a File [return new self($destination)]
   
but $file->getSize() crashes  saying "Call to a member function getSize() on true" 
Many thanks, Bill


RE: file->move returns 1 not a file - kenjis - 07-30-2024

You are probably using UploadedFile, not File.
See https://github.com/codeigniter4/CodeIgniter4/blob/f9d77a2e6ea002b9b274d8d98a11db9453a7602e/system/HTTP/Files/UploadedFile.php#L130-L132

But UploadedFile extends File. So changing the return type is a violation of LSP.


RE: file->move returns 1 not a file - badger - 07-31-2024

you're right (of course). I wasn't aware of Uploaded file. the source file is an upload and file->move(..) worked fine so i didn't search any further
thanks, Bill