I have been trying to get the fid of the file which my custom module is saving and every time I end up getting the error “Trying to get property of non-object in report()”. I have tried file_object->id() and file_object-> fid ->value but neither are working. This is my code in .module file:
function file_write($source , $name) { $uri = file_default_scheme() . '://'.$name.'.txt'; $file_object = file_save_data($source, $uri, FILE_EXISTS_REPLACE); return $file_object; }
And this is where how I call it and try to get fid:
$file_object = file_write($source, $name); $fid = $file_object->fid->value;
Is there anything wrong with the code? I also tried using other methods, but no luck so far.