0
Hello, I am building an application with PHP, I happen to have a button that when clicking it generates a file.xml in the downloads folder,I believe by default,but I want to generate this file.xml in a specific Folder that stores my files.xml.
I saw some examples using the function preg_match,but it only changed the name of the file by adding an underline or dot,.
This is my code to generate the person xml:
<?php
class RetornaPessoa_XML{
public function Pessoa_xmlGen($pessoaweb_id){
require_once('connection.php');
$sql = "SELECT pessoas.pessoaweb_id,
pessoas.nome,
pessoas.cpf_cnpj,
pessoas.rg_ie
FROM pessoas
WHERE pessoas.pessoaweb_id =".$pessoaweb_id;
$stmt = ibase_query($conn, $sql);
$data = [];
$i = 0;
$fileName = "../_xxx_Pessoa_id-".$pessoaweb_id;
while($row = ibase_fetch_assoc($stmt)){
$data[$i]['pessoaweb_id'] = $pessoaweb_id;
$data[$i]['nome'] = $row['NOME'];
$data[$i]['cpf_cnpj'] = $row['CPF_CNPJ'];
$data[$i]['rg_ie'] = $row['RG_IE'];
$i++;
}
//CHAMA A CLASSE EXPORT, COLOCA DENTRO DE UMA VARIÁVEL
//E EM SEGUIDA USA SUA FUNÇÃO, QUE MONTA E RETORNA UM ARQUIVO XML
require_once('pessoa_setXML.php');
$export = new Export();
if(isset($pessoaweb_id)){
$export->xml($fileName, $data, $pessoaweb_id);
}
// echo "<script>alert('chegou 2!');</script>";
return true;
}
}
?>
AND HERE IS THE CODE TO SET XML,ASSEMBLE XML WITH THE PROVIDED PARAMETERS
class Export{
public function xml($fileName, $data, $pessoaweb_id){
//RECEBE AS INFORMAÇÕES POR PARÂMETRO E MONTA O XML COM OS DADOS FORNECIDOS
$file = "{$fileName}.xml";
$xml = "<?xml version='1.0' encoding='UTF-8' ?>";
$xml .= "<DATAPACKET VERSION='1.0'>";
$xml .= "<METADATA>";
$xml .= "<FIELDS>";
$xml .= "<FIELD WIDHT='64' FIELDTYPE='Integer' ATTRNAME='PESSOA_ID'/>";
$xml .= "<FIELD WIDHT='64' FIELDTYPE='Integer' ATTRNAME='NOME'/>";
$xml .= "<FIELD WIDHT='64' FIELDTYPE='Integer'
ATTRNAME='NOMEFANTASIA'/>";
$xml .= "<FIELD WIDHT='300' FIELDTYPE='Integer' ATTRNAME='CPF_CNPJ'/>";
$xml .= "<FIELD WIDHT='300' FIELDTYPE='Integer' ATTRNAME='RG_IE'/>";
$xml .= "<FIELD WIDHT='300' FIELDTYPE='Integer'
ATTRNAME='PESSOAWEB_ID'/>";
$xml .= "</FIELDS>";
$xml .= "</METADATA>";
$xml .= "<{$fileName}>";
$xml .= "<ROWDATA>";
for($i = 0; $i < count($data);$i++){
$xml .= "<ROW>";
$xml .= "<ROW PEDIDOWEB_ID='{$data[$i]['pessoaweb_id']}'
RG_IE='{$data[$i]['rg_ie']}'
CPF_CNPJ='{$data[$i]['cpf_cnpj']}'
NOMEFANTASIA='NOMEFANTASIA'
NOME='{$data[$i]['nome']}' PESSOA_ID='PESSOA_ID'/>";
$xml .= "</ROW>";
}
$xml .= "</ROWDATA>";
$xml .= "</{$fileName}>";
$xml .= "</DATAPACKET>";
// CONFIGURA O HEADER PARA DOWNLOAD
header("Content-Description: PHP Generated Data");
header("Content-Type: application/xml");
header("Content-Disposition: attachment; filename=\"{$file}\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
// ENVIA CONTEÚDO
echo $xml;
}
}
Have you tried to define the absolute path in
$fileName
? Remember to check the directory permissions.– Woss
It would be the Downloads folder of your computer?
– Claudio Gonçalves Filho
You are downloading this file to c: DOWNLOADS by default, but I want you to upload it to Folder c: AQR_XML
– J. Moura