View previous topic :: View next topic |
Author |
Message |
mtbiking -
Joined: 18 Mar 2004 Posts: 66
|
Posted: Wed Dec 22, 2004 2:22 am Post subject: look for Txt file then if / else |
|
|
hi i need a php script that will
be like this
<?
$user = $_GET['id'];
if (!$_GET['id']) {
echo "Message.";
}
else {
$path = 'counter';
if(is_dir($path))
{
$count=$count + 1 ;
echo "message2";
$data = fopen("$path/$user.txt","w");
fwrite($data, $count);
fclose($data);
}
else
{
$self = $_SERVER["PHP_SELF"];
$host = $_SERVER["HTTP_HOST"];
mkdir($path);
header("Location: http://$host$self?id=$user");
}
}
?>
but it will first look in path for a file by that name and if it finds it return a different message
thanks in advance |
|
Back to top |
|
 |
Glitch2082 -
Joined: 02 Dec 2004 Posts: 194
|
Posted: Wed Dec 22, 2004 2:38 am Post subject: |
|
|
I think what your looking for is found in the php manual from php.net ... Ill post it here though to save time :D
Code: |
<?php
// --------------------------------------------
// http://us2.php.net/function.file-exists
// --------------------------------------------
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
// Glitch Comments:
// $filename being the path to your file (in your case $user, $count, etc)
// first it will check with file_exists, then if it doesn't it does the else {
?>
|
Hope I helped :D _________________ int main() {
cout << "Im Pro Apache";
cin.get();
} |
|
Back to top |
|
 |
mtbiking -
Joined: 18 Mar 2004 Posts: 66
|
Posted: Thu Dec 23, 2004 5:51 am Post subject: |
|
|
Code: |
<?php
$user = $_GET['id'];
$path = 'dir';
if (!$_GET['id'])
{
echo "no id";
}
else{
if (file_exists($path/$user.txt))
{
echo "The id $user exists";
}
else {
if (is_dir($path))
{
$count=$count +1;
echo "$user has been created.";
$data = fopen("$path/$user.txt","w");
fwrite($data, $count);
fclose($data);
}
}
}
?>
|
thats what i put together but it brings this out
if their is ?id=? not already created
Warning: Division by zero in C:\Program Files\Abyss Web Server2\htdocs\copy.php on line 9
fred has been created.
if their is ?id=? already created
Warning: Division by zero in C:\Program Files\Abyss Web Server2\htdocs\copy.php on line 9
fred has been created.
no ?id= works fine i get
no id |
|
Back to top |
|
 |
Anonymoose -
Joined: 09 Sep 2003 Posts: 2192
|
Posted: Thu Dec 23, 2004 12:55 pm Post subject: |
|
|
(file_exists($path/$user.txt))
You're asking it to divide $path by $user.
(file_exists("$path/$user.txt"))
Should work. |
|
Back to top |
|
 |
mtbiking -
Joined: 18 Mar 2004 Posts: 66
|
Posted: Thu Dec 23, 2004 9:17 pm Post subject: |
|
|
thanks
it works now |
|
Back to top |
|
 |
|