prezident Posted December 29, 2010 Share Posted December 29, 2010 $DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT']; $outputstring = $date."\t".$tireqty." tires \t".$oilqty."oil\t".$sparkqty." spark plugs\t\$".$totalamount."\t".$address."\n"; //open file for appending @$fp = fopen('$DOCUMENT_ROOT/../orders/orders.txt', 'ab'); if (!$fp) { echo '<p><strong>Your order can not be processed at this time. Please try again later</strong></p></body></html>'; exit; } //write to file fwrite($fp, $outputstring, strlen($outputstring)); flock($fp, LOCK_UN); fclose($fp); Can someone please explain to me why this Code is giving me the error? i've tried to take out $DOCUMENT_ROOT and specify where exactly i want the file to be /dir/dir/file.txt but it still gives me an error. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 29, 2010 Share Posted December 29, 2010 Remove the "@" which suppresses any error messages and see what error is produced. Ken Quote Link to comment Share on other sites More sharing options...
prezident Posted December 29, 2010 Author Share Posted December 29, 2010 Warning: fopen($DOCUMENT_ROOT/.../orders/orders.txt): failed to open stream: No such file or directory in /var/www/process.php on line 68 doesn't 'ab' <- append attempt to create the file ? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 29, 2010 Share Posted December 29, 2010 Since you are using single quotes around the filename, variables aren't evaluated. Use double quotes: <?php $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); ?> Ken Quote Link to comment Share on other sites More sharing options...
prezident Posted December 29, 2010 Author Share Posted December 29, 2010 Thanx but, now it's generating the warning: Warning: fopen(/var/www/.../orders/orders.txt): failed to open stream: No such file or directory in /var/www/process.php on line 68 Quote Link to comment Share on other sites More sharing options...
prezident Posted December 29, 2010 Author Share Posted December 29, 2010 I got it to work $fp = fopen("$DOCUMENT_ROOT/orders.txt", 'ab'); the file is in the main dir.. Thanx ken Quote Link to comment Share on other sites More sharing options...
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.