Hi, again I was am trying to use php and forms together with this code:
?php
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
print "The file $filename exists";
} else {
print "The file $filename does not exist";
}
?>
I was wondering if it is possible to use that with a text box and a submit button. I tried it and this is the code I have. I am new at the php coding stuff, so bare with me
Code I attempted:
form name="form1" method="post" action="">
<input type="text" name="$path" value="path to file here">
<input type="submit" name="$filename" value="Submit">
</form>
<p>
<?php
$filename = '$path';
if (file_exists($filename)) {
print "The file $filename exists";
} else {
print "The file $filename does not exist";
}
?>
Thanks, I made a effort at it.Hi,
If you put the php code into the file you specify in the form action attribute then once the form is submitted it'll let you know whether file exists or not. It won't work the way you have it there as what you have requires user input and php will already have parsed the page before the code reaches the user.
Regards,
RobertOk, thanks man. Do you think you can show me a example with a php code that would work with a text box and user input. And help me with what ones will work and want not to do?
Thanks.hmmmm... how about something like this?
<? if ($_POST['submit'] {
$filename = $_POST['path'];
if (file_exists($filename)) {
print "The file $filename exists";
} else {
print "The file $filename does not exist";
}
} else {?>
<form name="form1" method="post" action="<?$_SERVER[PHP_SELF]?>">
<input type="text" name="path" value="path to file here">
<input type="submit" name="submit" value="Submit">
</form>
<? }?>Thanks, I tried it and got a parsed error:
Parse error: parse error in mypathhere/www/delete.php on line 9
And line 9 is a space, haha. I am trying to figure it out.
And 662C [Robert] would this be able to work with a form? to connect to a ftp acc./server.
<?php
$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
?>
I just have to get the jist of it and I can start doing this on my own.
Thanks.Originally posted by xxnfg618xx
Thanks, I tried it and got a parsed error:
Parse error: parse error in mypathhere/www/delete.php on line 9
And line 9 is a space, haha. I am trying to figure it out.
That could be! I didn't actually try the code, I just wrote it off the top of my head so you can use as direction I guess... something to go on!forgot a ) on this line
<? if ($_POST['submit'] {
and always use quotes on this
$_SERVER['PHP_SELF']<? if ($_POST['submit']) {
and i don't see how anything could'nt work with form since it's a way to get value from the script...
like all the other way of getting value: session/cookie/file/db/etc
the only glitch is that a checkbox that is not check is not send when posting... (to my knowledge)there you go... that's what you get for typing fast and off the top of your head. haha, I have another question. Could this code be put in to a form?
<?php
$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
?>Originally posted by xxnfg618xx
haha, I have another question. Could this code be put in to a form?
you lost me xxnfg618xx: why not??ok more verbose mode on!
<?php
if (isset($_POST['server']))
{
$ftp_server = $_POST['server'];
$ftp_user = $_POST['user'];
$ftp_pass = $_POST['pass'];
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="server"><br>
<input type="text" name="user"><br>
<input type="password" name="pass"><br>
<input type="submit">
</form>thanks man, I think I am starting to get to know php coding a bit better, haha.
I logged in to my acc. to test it and is there a way to diplay the files, like open it in a browser. I tried going over to the php.net funcion list but I couldnt find anything? Do you have idea what I should look for?
Thanks,yeah, use an ftp program it is a lot easier. haha, I know I just want to get to know PHP and using it with forms, haha.
Nice one scoutt.<textarea><?php readfile('yourphpfile.php'); ?></textarea>
?php
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
print "The file $filename exists";
} else {
print "The file $filename does not exist";
}
?>
I was wondering if it is possible to use that with a text box and a submit button. I tried it and this is the code I have. I am new at the php coding stuff, so bare with me
Code I attempted:
form name="form1" method="post" action="">
<input type="text" name="$path" value="path to file here">
<input type="submit" name="$filename" value="Submit">
</form>
<p>
<?php
$filename = '$path';
if (file_exists($filename)) {
print "The file $filename exists";
} else {
print "The file $filename does not exist";
}
?>
Thanks, I made a effort at it.Hi,
If you put the php code into the file you specify in the form action attribute then once the form is submitted it'll let you know whether file exists or not. It won't work the way you have it there as what you have requires user input and php will already have parsed the page before the code reaches the user.
Regards,
RobertOk, thanks man. Do you think you can show me a example with a php code that would work with a text box and user input. And help me with what ones will work and want not to do?
Thanks.hmmmm... how about something like this?
<? if ($_POST['submit'] {
$filename = $_POST['path'];
if (file_exists($filename)) {
print "The file $filename exists";
} else {
print "The file $filename does not exist";
}
} else {?>
<form name="form1" method="post" action="<?$_SERVER[PHP_SELF]?>">
<input type="text" name="path" value="path to file here">
<input type="submit" name="submit" value="Submit">
</form>
<? }?>Thanks, I tried it and got a parsed error:
Parse error: parse error in mypathhere/www/delete.php on line 9
And line 9 is a space, haha. I am trying to figure it out.
And 662C [Robert] would this be able to work with a form? to connect to a ftp acc./server.
<?php
$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
?>
I just have to get the jist of it and I can start doing this on my own.
Thanks.Originally posted by xxnfg618xx
Thanks, I tried it and got a parsed error:
Parse error: parse error in mypathhere/www/delete.php on line 9
And line 9 is a space, haha. I am trying to figure it out.
That could be! I didn't actually try the code, I just wrote it off the top of my head so you can use as direction I guess... something to go on!forgot a ) on this line
<? if ($_POST['submit'] {
and always use quotes on this
$_SERVER['PHP_SELF']<? if ($_POST['submit']) {
and i don't see how anything could'nt work with form since it's a way to get value from the script...
like all the other way of getting value: session/cookie/file/db/etc
the only glitch is that a checkbox that is not check is not send when posting... (to my knowledge)there you go... that's what you get for typing fast and off the top of your head. haha, I have another question. Could this code be put in to a form?
<?php
$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
?>Originally posted by xxnfg618xx
haha, I have another question. Could this code be put in to a form?
you lost me xxnfg618xx: why not??ok more verbose mode on!
<?php
if (isset($_POST['server']))
{
$ftp_server = $_POST['server'];
$ftp_user = $_POST['user'];
$ftp_pass = $_POST['pass'];
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="server"><br>
<input type="text" name="user"><br>
<input type="password" name="pass"><br>
<input type="submit">
</form>thanks man, I think I am starting to get to know php coding a bit better, haha.
I logged in to my acc. to test it and is there a way to diplay the files, like open it in a browser. I tried going over to the php.net funcion list but I couldnt find anything? Do you have idea what I should look for?
Thanks,yeah, use an ftp program it is a lot easier. haha, I know I just want to get to know PHP and using it with forms, haha.
Nice one scoutt.<textarea><?php readfile('yourphpfile.php'); ?></textarea>