ivey Posted August 25, 2007 Share Posted August 25, 2007 Hi there, i don't know why this is so difficult. i just accessed apache and php on my mac. i'm going through Luke Welling and Laura Thomsons' PHP and MySQL Web Development. It's the Bob's Auto Parts bit... anwyay, the first problem was that when i tried to use fopen() it would not create a new file that didn't already exist. so i just tried putting the file where it needed to be manually, but now it still won't write to it. what's my problem? oh yes, and i checked the permission for the file i created manually and it is 644. so i tried to chmod it, but it wouldn't let me chmod it. so i tried to chown it, but that didn't work either. i got the following: Warning: chown() [function.chown]: Operation not permitted in /Users/ivey/Sites/phppractice/processor.php on line 22 Warning: chmod() [function.chmod]: Operation not permitted in /Users/ivey/Sites/phppractice/processor.php on line 22 here's the code i'm using: <?php //create short variable names $tire = $_POST['tire_qty']; $oil = $_POST['oil_qty']; $spark = $_POST['spark_qty']; $total_qty = 0; $total_amount = 0.00; $address = $_POST['address']; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <h2>Bob's Auto Parts</h2> <h3>Order Results</h3> <?php $date = date ('H:i, F jS'); echo '<p> Order results at '; echo $date; echo '</p>'; echo '<p> Your order is as follows:</p>'; $total_qty = $tire + $oil + $spark; echo 'Items ordered: '.$total_qty.'<br />'; $total_amount = $tire * TIREPRICE + $oil * OILPRICE + $spark * SPARKPRICE; $total_amount=number_format($total_amount, 2, '.', ' '); echo '<p>Total of order is '.$total_amount.'</p>'; echo '<p>Address to ship to is '.$address.'</p>'; $file = 'orders/orders.txt'; chown($file, nobody); chmod($file, 0777); //opening file $outputstring = $date."\t".$tire." tires \t".$oil." oil \t".$spark." spark plugs\t$".$total_amount."\t". $address."\n"; //open file for appending @ $fp = fopen("DOCUMENT_ROOT/orders/orders.txt", 'ab'); if(!$fp) { echo '<p><strong>Your order could not be placed at this time. ' .'Please try again.</strong></p></body></html>'; exit; } fwrite($fp, $outputstring, strlen($outputstring)); fclose($fp); ?> </body> </html> thanks so much for your help!!!! Quote Link to comment https://forums.phpfreaks.com/topic/66670-beginner-having-trouble-with-basic-fopen/ Share on other sites More sharing options...
dani9990 Posted August 25, 2007 Share Posted August 25, 2007 replace: @ $fp = fopen("DOCUMENT_ROOT/orders/orders.txt", 'ab'); WITH @ $fp = fopen("orders/orders.txt", 'ab'); Quote Link to comment https://forums.phpfreaks.com/topic/66670-beginner-having-trouble-with-basic-fopen/#findComment-334034 Share on other sites More sharing options...
ivey Posted August 25, 2007 Author Share Posted August 25, 2007 i tried that too... now i'm not sure if the problem is my permissions since i checked and they are set at 644? Quote Link to comment https://forums.phpfreaks.com/topic/66670-beginner-having-trouble-with-basic-fopen/#findComment-334035 Share on other sites More sharing options...
dani9990 Posted August 25, 2007 Share Posted August 25, 2007 this actually is a permission problme try setting your permissions to 777 Quote Link to comment https://forums.phpfreaks.com/topic/66670-beginner-having-trouble-with-basic-fopen/#findComment-334038 Share on other sites More sharing options...
ivey Posted August 25, 2007 Author Share Posted August 25, 2007 i did try changing the permission, but it wouldn't let me. is this some kind of a mac problem? and, by the way, the php manual says specifically that 'a' is supposed to append a file if it is there and CREATE it if it is not there. why won't it just create a file? if i delete the file i created manually, it still gives me the error. i feel like i'm going insane. does this work for other people? thanks so much for your help. i've been messing with this for hours... i Quote Link to comment https://forums.phpfreaks.com/topic/66670-beginner-having-trouble-with-basic-fopen/#findComment-334039 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.