writing to a txt document from mysql to my pc...
Posted: Fri Feb 13, 2004 11:18 am
i ppl...
since my 1st question (with your help...) i've evolved a little but... sometimes even the developer crashes... so i'v a question to the forum.
i've tried for several hours to solve the problem,
with no sucess so i decided to ask for help from the gurus...
this is my code
i'm trying to write a ????.txt from a table on mysql DB.
*************************
<?
include("liga_bd.php");
$ligacao = mysql_connect($hostname_noticias, $username_noticias, $password_noticias);
$ok = mysql_select_db("my_bd",$ligacao);
$caminho = $_GET['caminho_local'] // c:\data\
?>
<html>
<head>
<title>escreve</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$query ="SELECT *FROM `my_table` where num_f = '5764671'";
$result = mysql_query($query);
$registo = mysql_fetch_array($result);
$cont = $registo['data_f']." \r\n ".$registo['tit_f']."\r\n ".$registo['corpo_f'];
$nomefich = $caminho.$registo['num_f'].".txt";
if (is_writable('$nomefich'))
{
if (!$handle=fopen('$nomefich','a+'))
{
echo "Erro ao abrir o ficheiro ($nome_fich)";
exit;
}
if (!fwrite($handle, $cont))
{
echo "Erro ao escrever no ficheiro ($nome_fich)";
exit;
}
else
{
echo "sucesso... a string foi escrita para ($nomefich)";
}
}
else
{
echo "erro: O ficheiro ($nomefich) não pode ser escrito";
exit;
}
fclose($handle);
?>
</body>
</html>
******************************
well in the end the result is "sucesso... a string foi escrita para (c:\data\5764671.txt)" but my folder \data\ is totaly empty...
so i'll appreciate your help
thks in advance
since my 1st question (with your help...) i've evolved a little but... sometimes even the developer crashes... so i'v a question to the forum.
i've tried for several hours to solve the problem,
this is my code
i'm trying to write a ????.txt from a table on mysql DB.
*************************
<?
include("liga_bd.php");
$ligacao = mysql_connect($hostname_noticias, $username_noticias, $password_noticias);
$ok = mysql_select_db("my_bd",$ligacao);
$caminho = $_GET['caminho_local'] // c:\data\
?>
<html>
<head>
<title>escreve</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$query ="SELECT *FROM `my_table` where num_f = '5764671'";
$result = mysql_query($query);
$registo = mysql_fetch_array($result);
$cont = $registo['data_f']." \r\n ".$registo['tit_f']."\r\n ".$registo['corpo_f'];
$nomefich = $caminho.$registo['num_f'].".txt";
if (is_writable('$nomefich'))
{
if (!$handle=fopen('$nomefich','a+'))
{
echo "Erro ao abrir o ficheiro ($nome_fich)";
exit;
}
if (!fwrite($handle, $cont))
{
echo "Erro ao escrever no ficheiro ($nome_fich)";
exit;
}
else
{
echo "sucesso... a string foi escrita para ($nomefich)";
}
}
else
{
echo "erro: O ficheiro ($nomefich) não pode ser escrito";
exit;
}
fclose($handle);
?>
</body>
</html>
******************************
well in the end the result is "sucesso... a string foi escrita para (c:\data\5764671.txt)" but my folder \data\ is totaly empty...
so i'll appreciate your help
thks in advance