look for Txt file then if / else

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
mtbiking
-


Joined: 18 Mar 2004
Posts: 66

PostPosted: Wed Dec 22, 2004 2:22 am    Post subject: look for Txt file then if / else Reply with quote

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 View user's profile Send private message
Glitch2082
-


Joined: 02 Dec 2004
Posts: 194

PostPosted: Wed Dec 22, 2004 2:38 am    Post subject: Reply with quote

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 View user's profile Send private message Send e-mail
mtbiking
-


Joined: 18 Mar 2004
Posts: 66

PostPosted: Thu Dec 23, 2004 5:51 am    Post subject: Reply with quote

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 View user's profile Send private message
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Thu Dec 23, 2004 12:55 pm    Post subject: Reply with quote

(file_exists($path/$user.txt))

You're asking it to divide $path by $user.

(file_exists("$path/$user.txt"))

Should work.
Back to top View user's profile Send private message
mtbiking
-


Joined: 18 Mar 2004
Posts: 66

PostPosted: Thu Dec 23, 2004 9:17 pm    Post subject: Reply with quote

thanks

it works now
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group