Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Erro com a função fopen


Question

Bomm.. estou seguindo o livro PHP e MYSQL Desenvolvimento web e vendo um exemplo dado pelo livro aparece o seguinte erro "Warning: fopen(DOCUMENT_ROOT/../orders/orders.txt) [function.fopen]: failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\.. online 69

bom.. no livro explica esse erro de forma confusa. Gostaria de saber se alguém poderia me ajudar a corrigir o erro e explicar como funciona.

segue o codigo abaixo:


<html>
<head><title>Bob's Auto Parts</title></head>

<body>
<form action="process.php" method="post">
<table border="0">
<tr bgcolor="#cccccc">
<td width="150">Item</td>
<td width="15">Quantidade</td>
</tr>
<tr>
<td>Pneus</td>
<td align="left"><input type="text" name="pneusqnt" size="3" maxlength="3"></td>
</tr>
<tr>
<td>Óleo</td>
<td align="left"><input type="text" name="oleoqnt" size="3" maxlength="3"></td>
</tr>
<tr>
<td>Plugs</td>
<td align="left"><input type="text" name="plugsqnt" size="3" maxlength="3"></td>
</tr>
<tr>
<td>Address</td>
<td align="center"><input type="text" name="address" size="50" maxlength="150"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Mandar Ordem"></td>
</tr>
<tr>
<td>Como você achou o Bob's</td>
<td><select name="find">
<option value="a">Regular consumidor
<option value="b">TV
<option value="c">Fone
<option value="d">Blablabla
</select>
</td>
</tr>
</table>
</form>
</body>
</html>


//ARQUIVO PROCESS.PHP abaixo



<?php
$pneusqnt = $_POST['pneusqnt'];
$oleoqnt = $_POST['oleoqnt'];
$plugsqnt = $_POST['plugsqnt'];
$find = $_POST['find'];
$address = $_POST['address'];

$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];

?>
<html>
<head>
<title>Bob's Auto Parts Resultados</title>
</head>

<body>
<h1>Bob's Auto Parts</h1>
<h2>Ordem de Resultados</h2>
<?php
$date = date('H:i, jS F');
//escreve na tela as info processadas e hora/data

echo "<p>Suas ordens foram:";
echo $date;
echo "</p>";

echo "$pneusqnt Pneus <br />";
echo "$oleoqnt Óleo <br />";
echo "$plugsqnt Plugs <br />";

$totalqnt = 0;
$totalqnt = $pneusqnt + $plugsqnt + $oleoqnt;
echo "Total da ordem dos itens: $totalqnt";

if ($totalqnt==0) {
echo "<font color=red>";
echo "Você não colocou nada na página anterior!<br />";
echo "</font>";
}
else
{
if($pneusqnt>0)
echo "$pneusqnt Pneus<br />";
if($oleoqnt>0)
echo "$oleoqnt Óleo<br />";
if($plugsqnt>0)
echo"$plugsqnt Plugs</br />";
}

$totalamount = 0.00;

define('PNEUSPRECO', 100);
define('OLEOPRECO', 10);
define('PLUGSPRECO', 4);

$totalamount = $pneusqnt * PNEUSPRECO
+ $oleoqnt * OLEOPRECO
+ $plugsqnt * PLUGSPRECO;

$totalamount = number_format($totalamount,2, '.',' ');

echo "<p>Total das ordens foi: $totalamount</p>";
echo "<p>Endereço a ser enviado: $address</p>";

$outputstrings = $date."\t".$pneusqnt."Pneus \t".$oleoqnt."Oleo \t".$plugsqnt."Plugs\t\$".
$totalamount."\t".$address."\n";

//abre o arquivo para anexar
fp = fopen ("DOCUMENT_ROOT/../orders.txt",'ab');

if (!$fp)
{
echo "<p><strong>Suas ordens não puderam ser processas. Por favor tente mais tarde
</strong></p></body></html>";
exit;
}

fwrite($fp, $outputstring, strlen($outputstring));
fclose($fp);

echo "<p>Escreva as ordens</p>";
?>
</body>

</html>

[/codebox]

valeu ai gente. Abç

Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149296
    • Total Posts
      645693
×
×
  • Create New...