$fp=fopen("$DOCUMENT_ROOT/../chapter02/orders.txt",'w')中的..应该填写你的完整路径!

解决方案 »

  1.   

    D:/Program Files/php/xampp/htdocs/../chapter02/orders.txt

    D:/Program Files/php/xampp/htdocs/ 是网站的根
    ../chapter02/orders.txt 是目标文件
    实际路径是 D:/Program Files/php/xampp/chapter02/orders.txt这就是说你要把文件写到网站以外,请确认这个事实
    另外请确认 D:/Program Files/php/xampp/chapter02 目录存在,且一般用户有写权限
      

  2.   

    参考了一下上面各位的解决方法,现在还是有问题,望大家帮帮忙,谢谢。现在的提示错误是:
    Warning: fopen(D:/Program Files/php/xampp/htdocs/../study/chapter02/orders.txt) [function.fopen]: failed to open stream: No such file or directory in D:\Program Files\php\xampp\htdocs\study\chapter02\processorder.php on line 8181行的代码就是 $fp=fopen("$DOCUMENT_ROOT/../study/chapter02/orders.txt",'w');
    failed to open stream: No such file or directory 这是什么意思啊?
    还有就是orders.txt的权限要怎么设置啊?
      

  3.   

    No such file or directory没有这样的文件或目录的意思。还是路径不对的问题,能不能把完整代码贴出来参考?
      

  4.   


    回楼上的,当然可以了,麻烦帮忙看看
    <?php
    //create short variable names
    $tireqty=$_POST['tireqty'];
    $oilqty=$_POST['oilqty'];
    $sparkqty=$_POST['sparkqty'];
    $find=$_POST['find'];
    $address=$_POST['address'];

    $DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT'];
    $outputstring=$data."\t".$tireqty."tires \t".$oilqty."oil\t".$sparkqty."spark plug\t$".$totalmount."\t".$address."\n";
    ?><head>
    <title>Bob's auto parts - order results</title>
    </head><body>
    <h1>Bob's auto parts</h1>
    <h2>order results</h2>
    <?php 
    echo '<p> order processed </p>';  
    ?><?php
    echo '<p> order processed at';
    echo date('H:i,j F');
    echo '<p>';
    ?>
    <?php $totalqty=0;
    $discount=0;
    $totalqty=$tireqty+$oilqty+$sparkqty;

    if($totalqty>10 && $totalqty<50)$discount=0.05;
    elseif($totalqty>=50 && $totalqty<100)$discount=0.1;
    elseif($totalqty>99)$discount=0.15; if($totalqty == 0)
    {
    echo '<font color="red">'.'you order nothing'.'</font>';
    }
    else
    {
    echo '<p>your order is as follows</p>';
    echo $tireqty . 'tires<br />';
    //echo "$tireqty tires<br />";
    echo $oilqty . 'bottles of oil<br />';
    echo $sparkqty . 'spark plugs<br />';
    echo "your address is $address<br />";
    //calculate

    echo 'items ordered :'.$totalqty.'<br />';
    $totalamount=0.00;
    define('TIREPRICE',100);
    define('OILPRICE',10);
    define('SPARKPRICE',4);
    echo 'you order'.$totalqty.'goods.you discount is'.$discount.'<br />';
    $totalamount=($tireprice*TIREPRICE+$soilqty*OILPRICE+$sparkqty*SPARKPRICE)*(1-$discount);
    echo 'subtotal: $'.number_format($totalamount,2).'<br />';
    $taxrate=0.10;
    $totalamount=$totalamount*(1+$taxrate);
    echo 'Total including tax: $'.number_format($totalamount,2).'<br />';

    switch($find)
    {
    case'a': echo 'regular customer <br />';
    break;
    case'b': echo 'Customer referred by tv advertising<br />';
    break;
    case'c': echo 'Customer referred by phone dirctory<br />';
    break;
    case'd': echo'Customer referrde by word of mouth<br />';
    break;
    default: echo 'Customer directly<br />';
    break;
    }
    }

    $fp=fopen("$DOCUMENT_ROOT/../study/chapter02/orders.txt",'w');
    @$fp=fopen("$DOCUMENT_ROOT/../study/chapter02/orders.txt",'w');
    if(!$fp)
    {
    echo '<p><strong>your order could not processed at this time.<br />'.'please try again later.</strong></p><br />';
    exit;
    }
    fwrite($fp,$outputstring,strlen($outputstring));
    ?>
    </body>
    </html>
      

  5.   

    上面的是订单提交处理页面,下面这个就是订单页面了。<head>
    <title>orderform</title>
    </head><body>
    <form action="processorder.php" method="post">
    <table border="0">
    <tr bgcolor="#cccccc">
    <td width="200">items</td>
    <td width="15">quantity</td>
    </tr>
    <tr>
    <td>tires</td>
    <td align="center"><input type="text" name="tireqty" size="3" maxlength="3" /></td>
    </tr>
    <tr>
    <td>oil</td>
    <td align="center"><input type="text" name="oilqty" size="3" maxlength="3"/></td>
    </tr>
    <tr>
    <td>spark plugs</td>
    <td align="center"><input type="text" name="sparkqty" size="3" maxlength="3" /></td>
    </tr>
    <tr>
    <td>address</td>
    <td align="center"><input type="text" name="address" size="10" maxlength="10" /></td>
    </tr>
    <tr>
    <td>how did you find Bob's?</td>
    <td><select name="find">
    <option value="a">i am a regular customer</option>
    <option value="b">tv advertising</option>
    <option value="c">phone directory</option>
    <option value="d">word of mouth</option>
    </select>
    </td>
    </tr>
    <tr>
    <td align="center" colspan="2"><input type="submit" value="submit order" /></td>
    </tr>
    </table>
    </form></body>
    </html>
      

  6.   

      $fp=fopen("$DOCUMENT_ROOT/../study/chapter02/orders.txt",'w');
        @$fp=fopen("$DOCUMENT_ROOT/../study/chapter02/orders.txt",'w');改为      //$fp=fopen("$DOCUMENT_ROOT/../study/chapter02/orders.txt",'w');
        @$fp=fopen("$DOCUMENT_ROOT/study/chapter02/orders.txt",'w');试试看!我试过可以,没有报错了。
    结果如下:
    Bob's auto parts
    order results
    order processed order processed at02:19,26 July
    your order is as follows1tires
    2bottles of oil
    3spark plugs
    your address is sdfsdg
    items ordered :6
    you order6goods.you discount is0
    subtotal: $12.00
    Total including tax: $13.20
    regular customer your order could not processed at this time.
    please try again later.