I am stuck in a point that should be easy but I couldn't figure it out.

To make a long story short; I uploaded manually some images to the public directory and now I want to register them as managed files but I am stuck for some time where I couldn't figure out how to do it.

I tried using system_retrieve_file but it seems to accept only URLs not local paths public:// as it uses cURL to get the file

Also, I tried using file_save_data with no luck as well for the same mentioned points.

Any ideas?

1 Answer 1


I ended up creating a new managed file, pretty easy as the following:

$user = \Drupal::currentUser()->id();
    $image = File::create([
    'uri' => $image_local_path,
    'uid' => $user,
    'status' => FILE_STATUS_PERMANENT,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.