Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix this warning: file_get_contents(): Unable to find the wrapper "public"?

I need to read some meta information from the downloaded file. But I do not know how to do it.

Here is my code:

// Path form field_file
$file = 'public://directory/filename.txt';
file_get_contents($file);

This code causes this warning:

Warning: file_get_contents(): Unable to find the wrapper "public" - did you forget to enable it when you configured PHP?

Any idea of what I am doing wrong, please?

like image 651
ya.teck Avatar asked Dec 09 '10 13:12

ya.teck


1 Answers

There are three internal stream wrappers private, public and temporary, they are defined in this file.

You may want file_get_mimetype(), file_get_contents is a PHP function and won't be aware of the drupal file api.

file_get_contents(drupal_realpath($file));

Would do the trick for reading.

For an upload take a look at file_save_upload()

like image 197
Jeremy French Avatar answered Sep 26 '22 10:09

Jeremy French