2017-03-24 78 views
0

我最近將項目移至活動VM實例,它在使用XAMPP開發和測試我的macOS盒期間完美運行。本質上,該Web應用程序有3個導出選項:XML,PDF和CSV。 XML工作正常,並使用SELECT語句創建,然後遍歷結果並將其推送到XML文件中。使用MySQL INTO OUTFILE不寫入tmp

不過,對於CSV和PDF導出(PDF使用TCPDF)我用:

CSV

INTO OUTFILE '/tmp/$department_name+feedback+$timestamp.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"; 

PDF

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); 

所以我不能確定,爲什麼當它寫入/ tmp目錄和PDF & CSV沒有了XML的作品,這是運行在Google雲端平臺VM實例。正如我之前所說的CSV & PDF輸出在我的macOS機器上正常工作。

回答

0

中顯示這​​個結果:

SHOW VARIABLES LIKE 'secure_file_priv'; 

如果結果不爲空,你可以在此目錄中只寫。

+0

這表明它只會寫入特殊的MySQL目錄,因此在配置中將其禁用,並且按預期工作! –

相關問題