PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have created a form to gather information from customer orders such as information and addresses and i`m trying to setup fopen() to open a text file for this I would like the folder that contains this text file to be C:\Program Files\Apache Group\Apache\Docs .. I got the following code from a website and would like to know if i`m headed in the right direction:
I am using PHP version 4.0.4pl with apache 2.0 and apache 1.3 ...
Also i`m abit new but would like to know if its possible to create a new page and access this file from the new page or can I add this to my processorder.php page that i have already created...
<?php
$fr = fopen('/tmp/test.txt', 'a+');
if(!$fr) {
echo "Error! Couldn't open the file.";
} else {
// $fr now can be used to represent the opened file
}
if(!fclose($fr)) {
echo "Error! Couldn't close the file.";
}
?>
<?php
$fr = fopen(C:\Program Files\Apache Group\Apache\Docs\orders.txt', 'a+');
if(!$fr) {
echo "Error! Couldn't open the file.";
} else {
// $fr now can be used to represent the opened file
}
if(!fclose($fr)) {
echo "Error! Couldn't close the file.";
}
?>
tags here.
Looks a bit queer, doesn't it?
If you run this script through the syntax checker of php (calling php -l <scriptfile name>) you get[quote]Errors parsing <scriptfile name>
PHP Parse error: parse error, unexpected ':' in <scriptfile name> on line 2
[/quote]
<?php
$fr = fopen('C:\Program Files\Apache Group\Apache\Docs\orders.txt', 'a+');
if(!$fr) {
echo "Error! Couldn't open the file.";
} else {
// $fr now can be used to represent the opened file
}
if(!fclose($fr)) {
echo "Error! Couldn't close the file.";
}
?>
this looks more consistent. Replace the \ by / and you're done.
Matching similar (single/double) quotes are important !
also, above need Write permission for the directory "C:/Program Files/Apache Group/Apache/Docs/".
You add above your code into processorder.php, as well it is also possible that you can create a new file and do "require_once('processorder.php')" in the new file. You might have to adjust the processorder.php, if you want to require_once() it.