Page 1 of 1

writing to a txt document from mysql to my pc...

Posted: Fri Feb 13, 2004 11:18 am
by pedrokas
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, :oops: 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

Posted: Fri Feb 13, 2004 11:27 am
by markl999
if (is_writable('$nomefich')) <-- you'de need to remove the single quotes otherwise it will evaluate to a literal $nomefich and not the actual value of $nomefich

Posted: Fri Feb 13, 2004 11:37 am
by pedrokas
ok! i've tried so many code...
that solve this problem... create a new one... now the error is the file cannot be writed...
this mean that the file is not writable
(i'm a administrator of the domain so i've full control access to my disk)the 1st thing i've tested it was the security of my folder...

Posted: Fri Feb 13, 2004 11:39 am
by markl999
if (!$handle=fopen('$nomefich','a+')) <-- did you remove the single quotes from $nomefich here too?

Posted: Fri Feb 13, 2004 11:44 am
by pedrokas
in my code (is in other pc with no access to net) that var didn't have the quotes... i copyied the code to a txt to put in this forum...