For the security reason my host provider not allowing to switch on allow_url_fopen in php.ini

I would like to use the function file_get_contents() , How to run my module without using this function because I require to open a file and get the content as well as write to the file.

Comments

xDudditzx’s picture

EDIT- sorry, I misread your question.

wr5aw’s picture

Are you using a URI or a system path?

phdhiren’s picture

I'm using the system path.. like listing directory and reading files etc.

wr5aw’s picture

function my_file_get_contents($file_path, $use_include_path=FALSE) {
  $buffer = '';
  if (file_exists($file_path)) {
    $file_pointer = fopen($file_path, 'rb', $use_include_path);
    if ($file_pointer) {
      $buffer = fread($file_pointer, filesize($file_path));
      fclose($file_pointer);
    }
  }
  return $buffer;
}

$file_path = dirname(__FILE__) . '/path/to/yourfile.ext';
// or '/path/to/yourfile.ext'
// or drupal_get_path('module', 'your_module_name') .'/path/to/yourfile.ext'

$content = my_file_get_contents($file_path);