我最近将一个项目移动到一个实时VM实例,它在使用XAMPP在我的macOS盒子上进行开发和测试时工作得很好。基本上,Web应用程序有3个导出选项:XML,PDF和CSV。 XML工作正常,使用SELECT语句创建,然后循环遍历结果并将其推送到XML文件中。
然而,对于CSV和PDF导出(PDF使用TCPDF),我使用了:
CSV
INTO OUTFILE '/tmp/$department_name+feedback+$timestamp.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
INTO OUTFILE '/tmp/$department_name+feedback+$timestamp.txt' FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'";
但是文件永远不会写入/ tmp。我认为这是一个权限问题,但该目录由root拥有,并具有所需的所有必要权限。
工作的XML代码如下:
$fileLocation = '/tmp/' . $location_name . '+feedback+' . $timestamp . '+.xml';
$sql = "SELECT CONCAT (e.name,' ', e.surname) AS Fullname, f.score AS Score, d.department_name AS Department, f.feedback AS Feedback
FROM employee AS e
JOIN feedback AS f
ON e.qr_id = f.qr_id
JOIN departments as d
ON e.department_id = d.department_id
JOIN location AS l
ON e.location_id = l.location_id
AND e.location_id = '$location'
AND e.company_id = '$company_id'
AND f.`report_Time` BETWEEN SUBDATE(CURDATE(),
INTERVAL 1 MONTH) AND NOW()
ORDER BY f.score DESC";
$xml = new XMLWriter();
$xml->openURI($fileLocation);
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('feedback');
foreach ($mysqli->query($sql) as $row){
$xml->startElement("Fullname");
$xml->writeRaw($row['Fullname']);
$xml->startElement("Score");
$xml->writeRaw($row['Score']);
$xml->startElement("Feedback");
$xml->writeRaw($row['Feedback']);
$xml->startElement("Department");
$xml->writeRaw($row['Department']);
$xml->endElement();
}
$xml->endElement();
header('Content-type: text/xml');
$xml->flush();
$file_url = $fileLocation;
header('Content-Type: application/xml');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
readfile($file_url);
所以我不确定为什么XML在写入/ tmp目录和PDF& CSV没有,这是在Google Cloud Platform VM实例上运行的。正如我之前所说的CSV& PDF导出在我的macOS机器上正常工作。
答案 0 :(得分:0)
显示结果:
SHOW VARIABLES LIKE 'secure_file_priv';
如果结果不为NULL,则只能在此目录中写入。