0

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.

1 Answer 1

0

In Drupal 7, $file_object->fid should work.

Looking at the code you have tried ($file_object->fid->value, file_object->id()), I guess you have been mixing up Drupal 8 and Drupal 7 documentation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.