1

I've got a mapped network drive 'Z://' and my PHP file is stored on my 'C://' drive. When trying to use opendir() or fopen() I keep getting the errors. The reason for the mapped drive is because I was having issues writing into the drive directly.

opendir (just mapped drive):

failed to open dir: No such file or directory [file] => C:\path-to-php-file\phpfile.php [line] => 2 )

fopen: (mapped drive then absolute path)

failed to open stream: No such file or directory [file] => C:\path-to-php-file\phpfile.php [line] => 2 )

failed to open stream: Permission denied [file] => C:\path-to-php-file\phpfile.php [line] => 2 )

EDIT - PHP code now below. I should note that I'm using a network drive as permissions weren't allowed with the absolute path despite having the folders missions shared. I'm also able to open/read/write files manually on the server folder and the network drive

<?php
if(fopen(('\\\\servername\\serverdirectory\\thecsvfile.csv'), "w+")){
    echo 'it worked!';
}
else{
    print_r(error_get_last()); //prints 'permission denied - which is why network drive has been mapped and given permissions'

if(fopen(('Z://thecsvfile.csv'), "w+")){
    echo 'it worked!';
}
else{
    print_r(error_get_last()); //prints 'No such file or directory...'
}
?>
Community
  • 1
  • 1
Chuck
  • 119
  • 3
  • 20

1 Answers1

1

A (less than ideal) solution to this problem I discovered is to create the csv in the same drive as the php files, drive 'C://' and then create a cron job in Windows Task Scheduler to run a .bat file to copy the file to the network drive every hour.

Chuck
  • 119
  • 3
  • 20