2011-07-29 7 views
0

생성 된 파일을 화면에 인쇄하는 대신 저장하려면 아래 코드를 어떻게 편집해야합니까?화면에 인쇄하는 대신 XML 파일로 내보내려면 어떻게해야합니까?

<?php 
header("Content-type: text/xml"); 

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 

$query = ""; 
$resultID = mysql_query($query, $linkID) or die("Data not found."); 

$xml_output = "<?xml version=\"1.0\"?>\n"; 
$xml_output .= "<products>\n"; 

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ 
    $row = mysql_fetch_assoc($resultID); 

    $xml_output .= "\t<product>\n"; 
. 
. 
. 
    $xml_output .= "\t</product>\n"; 
} 

$xml_output .= "</products>"; 

echo $xml_output; 
?> 
+1

중복 가능성을 [강제 PHP를 사용하여 파일을 다운로드하려면] (http://stackoverflow.com/questions/1465573/forcing-to-download-a-file-using-php) –

+0

로컬 파일에 저장하는 것을 의미하는 경우 예를 참조하십시오. http://www.tizag.com/phpT/filewrite.php – Giorgio

답변

3

"Content-Disposition"헤더를 사용하여 권장 파일 이름을 제공하고 웹 브라우저가 저장 대화 상자를 표시하도록합니다. 이것은 당신이 PHP 헤더 기능 페이지에 대한 자세한 정보를 찾을 수 있도록 모든 서버 설정 및 모든 브라우저에서 작동하지 않을 수 있습니다

<?php 
header('Content-type: text/xml'); 
header('Content-Disposition: attachment; filename="downloaded.xml"'); 

// ...your other code 
?> 

: 예를 들어

http://php.net/manual/en/function.header.php

관련 문제