help with php and text area?

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!

Moderator: General Moderators

Post Reply
jameslat
Forum Newbie
Posts: 7
Joined: Fri Feb 26, 2010 5:08 pm

help with php and text area?

Post by jameslat »

here is my code...

Code: Select all

 
<html>
<head></head>
<body>
<h2>Get er done</h2>
<?php
///by James Lat
if (!isset($_POST['submit'])){
?>
<form action = "<?php echo $SERVER['PHP_SELF']; ?>" method="post">
Upload your .txt file: <input name="myfile" size="10">
<input type="submit" name="submit" value="Upload">
</form>
<--help here-->
<form>
<form method="post"> 
<textarea cols="50" rows="4" name="edit"></textarea>  
</form>
<?php
}
else{
$myfile=$_POST['myfile'];
include("$myfile"); 
}
?>
</body>
</html>
 
I need some help. this program will ulpoad a .txt file, however i'm trying to make it uplaod the file to a text area.
how can i do this?
thanks to all! :D
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: help with php and text area?

Post by califdon »

jameslat wrote: i'm trying to make it uplaod the file to a text area.
how can i do this?
thanks to all! :D
I don't know what that means. A text area is an HTML element. "Uploading" a file means making a copy of the file on the server. There is no connection between the two. What is it you are trying to do?
jameslat
Forum Newbie
Posts: 7
Joined: Fri Feb 26, 2010 5:08 pm

Re: help with php and text area?

Post by jameslat »

ok i shouldn't say upload bc that's wrong terminology.
basicaly it's just grabing a file form on the server.

Code: Select all

 
<html>
<head></head>
<body>
<h2>Get er done</h2>
<?php
///by James Lat
if (!isset($_POST['submit'])){
?>
<form action = "<?php echo $SERVER['PHP_SELF']; ?>" method="post">
Upload your .txt file: <input name="myfile" size="10">
<input type="submit" name="submit" value="Upload">
</form>
<form>
<form method="post"> 
<textarea cols="50" rows="4" name="edit">
<?php
}
else{
$myfile=$_POST['myfile'];
include("$myfile"); 
}
?>
</textarea>  
</form>
</body>
</html>
 
i revised the code a little bit. basicaly i'm trying to get the file to be laoded into the text feild.
if u run this code as is it will load the text file, but not in the textarea box.
how can i make the file laod in the text area box?
thanks again.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: help with php and text area?

Post by califdon »

You'll have to write the code that determines where the uploaded file is to be stored on the computer, including what filename it will have, then you can include that file in the html textarea. There's a fair amount of php code required to do that. Read a tutorial about uploading files with php. There are a lot of decisions you'll have to make, like whether you're going to keep these files on the server forever, how you're going to name them, etc.
jameslat
Forum Newbie
Posts: 7
Joined: Fri Feb 26, 2010 5:08 pm

Re: help with php and text area?

Post by jameslat »

ok, but i'm not tying to uplaod a file.
i'm trying to take an existing file (that's already on the server) and load the code to a textarea feild.
how can i do this?
thanks.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: help with php and text area?

Post by califdon »

Your code says "Upload your .txt file" and your submit button says "Upload", but now you're saying you're not trying to upload a file? Could have fooled me.

So I have to guess that you're doing this on your own, local server. Otherwise, you couldn't expect a web visitor to know what filename and path to specify, right? In that case, all you need to do is use PHP to include the text file in the HTML textarea element (between the opening and closing tags):

Code: Select all

<?php
$filename = isset($_POST['myfile'] ? $_POST['myfile'] : "";
...
?>
...
<textarea rows=12 cols=40><?php include($filename);?></textarea>
...
jameslat
Forum Newbie
Posts: 7
Joined: Fri Feb 26, 2010 5:08 pm

Re: help with php and text area?

Post by jameslat »

it keeps telling me that i have a parse error?
jameslat
Forum Newbie
Posts: 7
Joined: Fri Feb 26, 2010 5:08 pm

Re: help with php and text area?

Post by jameslat »

it keeps telling me that i have a parse error?
how could i get the file to read it into the text area?
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: help with php and text area?

Post by mikosiko »

in this line:

Code: Select all

$filename = isset($_POST['myfile'] ? $_POST['myfile'] : "";
add a ) before the ; like this

Code: Select all

$filename = isset($_POST['myfile'] ? $_POST['myfile'] : ""[color=#FF0000])[/color];
and test
Miko
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: help with php and text area?

Post by califdon »

Yup, even us old-timers slip up now and then. But mikosiko got the wrong place to add the parenthesis. It needs to go before the "?" like this:

Code: Select all

$filename = isset($_POST['myfile']) ? $_POST['myfile']) : "";
because it's the closing parenthesis for the isset() function.

To help you with coding PHP, think of error messages as your friends! When it says "parse error" it's telling you that it can't understand what you want because you have not followed the syntax rules. So look for things like missing semicolons (;) at the end of lines, or unmatched brackets or parentheses (in this case) or only part of the statement, etc. Then you will find your errors fast. Since I was doing that one in my head, my head didn't give me any parse error.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: help with php and text area?

Post by mikosiko »

califdon wrote:Yup, even us old-timers slip up now and then. But mikosiko got the wrong place to add the parenthesis. It needs to go before the "?" like this:

Code: Select all

$filename = isset($_POST['myfile']) ? $_POST['myfile']) : "";
because it's the closing parenthesis for the isset() function.

To help you with coding PHP, think of error messages as your friends! When it says "parse error" it's telling you that it can't understand what you want because you have not followed the syntax rules. So look for things like missing semicolons (;) at the end of lines, or unmatched brackets or parentheses (in this case) or only part of the statement, etc. Then you will find your errors fast. Since I was doing that one in my head, my head didn't give me any parse error.
nah... just testing if you were awake ... (no really.. I had a brain f a r t )

I lost one point
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: help with php and text area?

Post by califdon »

Don't feel bad, mikosiko, it happens to everyone. :-) Thanks for contributing!
Post Reply