Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1708
  • Last Modified:

PHP access a Mapped network drive running on Xampp

I have a Xampp installation running on windows server 2003. This has a mapped network drive to a text file. I cannot read or even see the file with php (see code) I also tried fopen. I have full access to the file under windows.

I have set the Apache service to run as a domain administrator as a test however this still didn't work. I did this via the MMC service control panel logon as. option.
<?php
//file path of MEFILTER-BANNED.txt
 $filepath = "T:\\Config\\Filters\\Patterns\\MEFILTER-BANNED.txt";
 
 //file path of the log file
 $logpath = "log.txt";
 
 //file path of MEFILTER-BANNEDTEMP.txt
 $filepathtemp = "T:\\Config\\Filters\\Patterns\\MEFILTER-BANNEDTEMP.txt";
 
 if (file_exists($filepath)) {
    echo 'The file is readable';
} else {
    echo 'The file is not readable';
}
 
 
  $fh = fopen($filepath, 'a+') or exit("");
  $stringData = $_POST["domain"];
  fwrite($fh, "$stringData\r\n") or exit("");
  fclose($fh);
?>

Open in new window

0
purpleoak
Asked:
purpleoak
  • 2
  • 2
1 Solution
 
Beverley PortlockCommented:
Two suggestions for you

1. Use forward slashes in the filename and let PHP worry about  translating them to match the file system

2. If possible use UNC names rather than mapped drives  //server/path/to/folder/filename.txt

0
 
Beverley PortlockCommented:
Sorry - should have posted an example

Rather than

$filepath = "T:\\Config\\Filters\\Patterns\\MEFILTER-BANNED.txt";

use

$filepath = "T:/Config/Filters/Patterns/MEFILTER-BANNED.txt";
0
 
purpleoakAuthor Commented:
I will try the UNC name then however I have tried the forward slash, double single both directions. I perhaps should have mentioned that. Apologies.
0
 
purpleoakAuthor Commented:
UNC path names did the trick. thank you very much spent ages trying to figure that out.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now