我想使用php将MS SQL(2008R2)查询的结果写入远程共享驱动器。该驱动器具有访问控制权,但所有用户(包括我自己)都被批准访问。当我在我的服务器上运行fopen()和fputcsv()并将csv放在远程共享驱动器文件夹上时,它工作正常。当我尝试通过绑定到按钮(#testing)的AJAX调用执行php时,它给了我(用remoteDrive替换实际文件路径的地方:
fopen(\\ remoteDrive \ file.csv):无法打开流:第19行 C:\ inetpub \ wwwroot \ dart \ fetchdata.php 中的权限被拒绝
fetchdata.php:
<?php
try {
$dbh = new PDO("sqlsrv:Server=(local);Database=dart");
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo json_encode("Error connecting to the server.");
die ();
}
$query = "SELECT DISTINCT *
FROM dbo.table";
$sth = $dbh->prepare($query);
try {
$sth->execute();
$fp = fopen('\\\\remoteDrive\\file.csv','w');
$array = ["name","layer","type"];
fputcsv($fp,$array);
while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
fputcsv($fp,$row);
}
} catch (PDOException $e) {
header('Content-type: application/json');
echo json_encode("Error submitting the query.");
die ();
}
fclose($fp);
jQuery的:
$(document).on('click','#tester', function(event) {
$.ajax({
type: 'POST',
url: 'fetchdata.php',
success: function(result) {
alert(result);
},
error: function(result) {
alert(result);
}
})
})
非常感谢任何见解。