3

I am trying to open text file through PHP. The below code is working fine when I have text file inside the Project folder htdocs.

<?php
   $myfile = fopen("Updates/updates.txt", "r") or die("Unable to open file!");
   echo fread($myfile,filesize("HRupdates/updates.txt"));
   fclose($myfile);
?>

Now I would like to open file from another drive from drive D.

I tried like this D:/Updates/updates.txt it is not working. any other ways?

Maria Jeysingh Anbu
  • 3,164
  • 3
  • 34
  • 55
  • possible duplication of http://stackoverflow.com/questions/10311674/accessing-file-of-another-drive – Thamilhan Oct 30 '15 at 13:16
  • If you have enabled safe mode or open_basedir further restrictions may apply. http://php.net/manual/en/function.fopen.php – Lucky Chingi Oct 30 '15 at 13:19
  • http://stackoverflow.com/questions/6628863/path-to-a-file-in-a-different-drive says to use like this "D:\Updates\updates.txt" – Thamilhan Oct 30 '15 at 13:20

1 Answers1

2

Yes it has a way :) .Be careful to use forward slashes in the path to the file.

<?php

$file=fopen('G:\\webdic.txt', "r") or die('Unable to open file');

echo fread($file,filesize('G:\\webdic.txt'));

fclose($file);
?>

Here i am using G drive on my PC. and it is working .