vieworder.php
<?php
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
@ $fp= fopen("$DOCUMENT_ROOT/orders/orders.txt",'rb');
if(!$fp)
{
echo "<p><strong>No orders pending.Please try again later.</strong></p>";
exit;
}
while(!feof($fp))
{
$order= fgets($fp,999);
echo $order. '<br />';
}
?>
<p>Go to <a href ="vieworders2.php">ViewOrders2</a></p>
</body>
</html>
能够成功运行,如下:
Bob's Auto Parts
Customer Orders
22:32,16th May 2011 2 tires 4 oil 6 spark plugs $264.00 22 short St,Smalltown
22:33,16th May 2011 2 tires 40 oil 6 spark plugs $624.00 22 short St,Smalltown
可是换成另一种情况的时候就不行,高手看看
vieworder2.php
<?php
$DUCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
/*if(file_exists("$DOCUMENT_ROOT/orders/orders.txt"))
echo 'There are orders waiting to be processed.';
else
echo 'There are currently no orders.';
*/
$orders = file("$DOCUMENT_ROOT/orders/orders.txt");
$number_of_orders = count($orders);
if($number_of_orders == 0){
echo "<p><strong>No Orders pending.
Please try again later.</strong></p>";
}
echo "<table border =\"1\">\n";
echo "<tr><th bgcolor =\"#ccccff\">Order Date</th>
<th bgcolor =\"#ccccff\">Tires</th>
<th bgcolor =\"#ccccff\">Oil</th>
<th bgcolor =\"#ccccff\">Spark Plugs</th>
<th bgcolor =\"#ccccff\">Total</th>
<th bgcolor =\"#ccccff\">Address</th>
</tr>";
for($i=0; $i<number_of_orders;$i++)
{
$line = explore("\t",$orders[$i]);
$line[1] = intval($line[1]);
$line[2] = intval($line[2]);
$line[3] = intval($line[3]);
echo "<tr>
<td>".$line[0]."</td>
<td align=\"right\">".$line[1]."</td>
<td align=\"right\">".$line[2]."</td>
<td align=\"right\">".$line[3]."</td>
<td align=\"right\">".$line[4]."</td>
<td>".$line[5]."</td>
</tr>";
}
echo "</table>";
?>
</body>
</html>
就有以下的错误:
Bob's Auto Parts
Customer OrdersWarning: file(/orders/orders.txt) [function.file]: failed to open stream: No such file or directory in F:\AppServ\www\test\vieworders2.php on line 17
<?php
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
@ $fp= fopen("$DOCUMENT_ROOT/orders/orders.txt",'rb');
if(!$fp)
{
echo "<p><strong>No orders pending.Please try again later.</strong></p>";
exit;
}
while(!feof($fp))
{
$order= fgets($fp,999);
echo $order. '<br />';
}
?>
<p>Go to <a href ="vieworders2.php">ViewOrders2</a></p>
</body>
</html>
能够成功运行,如下:
Bob's Auto Parts
Customer Orders
22:32,16th May 2011 2 tires 4 oil 6 spark plugs $264.00 22 short St,Smalltown
22:33,16th May 2011 2 tires 40 oil 6 spark plugs $624.00 22 short St,Smalltown
可是换成另一种情况的时候就不行,高手看看
vieworder2.php
<?php
$DUCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
/*if(file_exists("$DOCUMENT_ROOT/orders/orders.txt"))
echo 'There are orders waiting to be processed.';
else
echo 'There are currently no orders.';
*/
$orders = file("$DOCUMENT_ROOT/orders/orders.txt");
$number_of_orders = count($orders);
if($number_of_orders == 0){
echo "<p><strong>No Orders pending.
Please try again later.</strong></p>";
}
echo "<table border =\"1\">\n";
echo "<tr><th bgcolor =\"#ccccff\">Order Date</th>
<th bgcolor =\"#ccccff\">Tires</th>
<th bgcolor =\"#ccccff\">Oil</th>
<th bgcolor =\"#ccccff\">Spark Plugs</th>
<th bgcolor =\"#ccccff\">Total</th>
<th bgcolor =\"#ccccff\">Address</th>
</tr>";
for($i=0; $i<number_of_orders;$i++)
{
$line = explore("\t",$orders[$i]);
$line[1] = intval($line[1]);
$line[2] = intval($line[2]);
$line[3] = intval($line[3]);
echo "<tr>
<td>".$line[0]."</td>
<td align=\"right\">".$line[1]."</td>
<td align=\"right\">".$line[2]."</td>
<td align=\"right\">".$line[3]."</td>
<td align=\"right\">".$line[4]."</td>
<td>".$line[5]."</td>
</tr>";
}
echo "</table>";
?>
</body>
</html>
就有以下的错误:
Bob's Auto Parts
Customer OrdersWarning: file(/orders/orders.txt) [function.file]: failed to open stream: No such file or directory in F:\AppServ\www\test\vieworders2.php on line 17
解决方案 »
- 在PHP下操作网络驱动器的方法
- php怎么停止程序执行?
- 如何处理带复选框的信息列表!!(大家来给点建议)
- 急 求助!!我的类哪里写错了 帮忙指下
- FTP上传的视频不能播放!!
- 使用require或include包含文件的时候出现找不到文件的错误,可文件明明存在,怎么办?
- 很菜地问一下,PHP里有没有以下几个东西,谢谢各位大虾!
- IMAP可以在windows下安装不?如何使用mail()
- 请问在下面的程序中: fputs($fp,"GET / HTTP/1.0\nHost: 192.168.0.127\n\n");中的GET / HTTP/1.0\nHost: 192.168.0.127\n\n是什么意思
- 求TP框架3.2分页具体教程
- PHPinfo中没有MySQL信息,怎样配置PHP?
- 为什么 不能上传图片
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
vieworder2.php 变量名字错了