I am trying to code as follows:


but if (file_exists($uri)) fails

the complete path


works and passes (file_exists($uri))

drupal_realpath('public://') returns /var/www/html/www.mydomain.com/sites/default/files

What am I missing here?

  • Why not try this $uri = drupal_realpath('public://').'admin/myfile.txt'; – Nabil Feb 4 '14 at 12:47
  • Thanks, I tried that earlier myself but it doesn't work either. – Karin Feb 4 '14 at 12:57
  • @Karin Dumb questions: Your public file system is correctly set and you're using PHP 5+? Did you run the checks mentioned here stackoverflow.com/questions/4634797/… ? – berliner Feb 4 '14 at 14:01

The path 'public://admin/myfile.txt' is not a real path (because of the 'public://'-part, which is a drupal-custom), it's a stream-wrapper-path (see link at end of answer).

file_exists() can only process real-paths and registered stream-wrapper-paths

This means for you: Either your Drupal-installation didn't register it's custom stream-wrapper or your server-isp deactivated the stream-wrappers on your server/account.

You should check your php-config for Filesystem and Streams Configuration Options: http://www.php.net/manual/en/filesystem.configuration.php

More info on php's stream-wrappers:

BTW: Registering of custom stream-wrappers is supported by PHP 4.3.2+

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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