简体   繁体   中英

Trying to open (and create if not exists) file on mapped network drive in PHP

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...'
}
?>

我发现的此问题的(不太理想的)解决方案是在与php文件相同的驱动器中创建csv,驱动器'C://',然后在Windows Task Scheduler中创建cron作业以运行.bat文件以每小时将文件复制到网络驱动器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM