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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pedrokas
Forum Commoner
Posts: 32
Joined: Thu Jan 15, 2004 10:53 am
Location: Lisboa, Portugal

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

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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
User avatar
pedrokas
Forum Commoner
Posts: 32
Joined: Thu Jan 15, 2004 10:53 am
Location: Lisboa, Portugal

Post 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...
Last edited by pedrokas on Fri Feb 13, 2004 11:40 am, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

if (!$handle=fopen('$nomefich','a+')) <-- did you remove the single quotes from $nomefich here too?
User avatar
pedrokas
Forum Commoner
Posts: 32
Joined: Thu Jan 15, 2004 10:53 am
Location: Lisboa, Portugal

Post 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...
Post Reply