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. Link to comment https://forums.phpfreaks.com/topic/222878-fopen-function-and-fwrite/ 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 Link to comment https://forums.phpfreaks.com/topic/222878-fopen-function-and-fwrite/#findComment-1152454 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 ? Link to comment https://forums.phpfreaks.com/topic/222878-fopen-function-and-fwrite/#findComment-1152455 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 Link to comment https://forums.phpfreaks.com/topic/222878-fopen-function-and-fwrite/#findComment-1152458 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 Link to comment https://forums.phpfreaks.com/topic/222878-fopen-function-and-fwrite/#findComment-1152460 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 Link to comment https://forums.phpfreaks.com/topic/222878-fopen-function-and-fwrite/#findComment-1152461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.