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';
fil开发者_运维技巧e_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?
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()
I believe that these wrappers aren't available in hook_boot()
or some other early stages.
So please move your code into another place and check if this would fix the problem.
The fix I'm using is the following code:
echo base_path().variable_get('file_public_path',conf_path().'/files');
It still doesn't explain why streams aren't working.
精彩评论