[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

TEXTAREA submission limit

I have a php/mysql page on one of the websites I work on that allows users to submit stories to a database for other uses to rate.  The problem is that I noticed that if there's too much text in the textarea where the story is put, nothing happens when I click the submit button.  I'm figure a separate possibility is to let a user upload a text file.  Could someone either tell me a way to get around the textarea limitation or give me a small simple script for allowing someone to upload a text file?  All the example scripts for uploads I have are way too complex; I would just need something simple that lets me upload a text file to the server and save it so I can just convert the saved file to a blob in the mysql db.  If you want to see exactly what I'm talking about, look at http://www.planetadnd.com/adv_tales/adv_submit.php
0
webhermit
Asked:
webhermit
1 Solution
 
higijjCommented:
Here is the form you need to use:

<FORM ACTION="upload.php" METHOD="post" ENCTYPE="multipart/form-data">
     <B>File: <B><INPUT TYPE="FILE" NAME="userfile"><BR><BR>
     <INPUT TYPE="submit" VALUE="Upload">
</FORM>



Here is the php script to deal with the file

upload.php:

<?
$basedir = "/usr/home/";

// if the user hasn't uploaded a .txt, exit
if ($userfile_type != "text/plain") {
     print "Error! Must be a txt file!";
     exit(1);
}

$directory = $basedir . "username";
// check to see if the directory already exists
// you would need to modify this if you don't want the file to
// overwrite a previous file of the SAME user

if (is_dir($directory) && $userfile) {

     if (copy($userfile, "$directory/story.txt.php")) {
          mail_admin();
          header("Location: after_upload.php");
     } else {
          print "<HTML><BODY>Error while uploading/saving your file. Please retry. If the error still happen, please contact us.</BODY></HTML>";
     }

} else { // if it is the first time the user uploads, create his directory

     mkdir($directory, 0755);

     if ($userfile) {

          if (copy($userfile, "$directory/story.txt")) {
               mail_admin();
               header("Location: after_upload.php");
          } else {
               print "<HTML><BODY>Error while uploading/saving your file. Please retry. If the error still happen, please contact us.</BODY></HTML>";
          }

     }
}


?>
0
 
daniel_cCommented:
I suggest you to do client-side script to limit textarea content.

Here is the simple example:
<html>
<head>
<script language=Javascript>

var textMax = 350; // Max length of text area = 350 chars

function checkLength(textareaObj) {
  if (textareaObj.value.length > textMax) {
     alert("Max. Length is 350 characters only!");
     textareaObj.focus();
     return false;
  }
  return true;
}

</script>
</head>
<body>
<form onSubmit="return checkLength(this.myText);">
Max. Length: 350 characters
<br>
<textarea name="myText"></textarea>
<br>
<input type-submit>
</form<
</body>
</html>

Hope this helps!

Cheers,

^_^
0
 
daniel_cCommented:
Oops, many typos! Here, it is again:

<html>
<head>
<script language=Javascript>

var textMax = 350; // Max length of text area = 350 chars

function checkLength(textareaObj) {
 if (textareaObj.value.length > textMax) {
    alert("Max. Length is 350 characters only!");
    textareaObj.focus();
    return false;
 }
 return true;
}

</script>
</head>
<body>
<form onSubmit="return checkLength(this.myText);">
Max. Length: 350 characters
<br>
<textarea name="myText"></textarea>
<br>
<input type=submit>
</form>
</body>
</html>
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
webhermitAuthor Commented:
Hig -
I'll try that out and see if it works right
daniel -
The point is that I need it to let me use more, not limit them, that script's the reverse of it.
0
 
meetygCommented:
Your problem is that you are sending the text in the querystring! (USING the GET method in your form!)
the querystring is limited to about 2000 characters (in Internet explorer 5).
You need to send it in a form using the POST method, for example:
-------------------------------------------------
<FORM ACTION="submit_text.php" METHOD="post" ENCTYPE="multipart/form-data">

<TEXTAREA name="StoryText">
</TEXTAREA>


</FORM>
------------------------------------------------

In PHP you will be able to use the same variable as you did for the GET method, unless the register_global_variables option is off. In any case, you can get the info from the textarea like this:
-----
$MyStoryText=$HTTP_POST_VARS["StoryText"];
-----



   
0
 
higijjCommented:
meetyg, read EE guideline about Proposed Answer!

you lock the question for other expert to add more comment!
if your answer is the best one, webhermit will give you the pts! ;-)
0
 
higijjCommented:
webhermit, feel free to reject the above answer ..
0
 
MoondancerCommented:
This question was LOCKED with a PROPOSED ANSWER and awaits your decision today.  Once a question is LOCKED with a Proposed Answer, few new experts will step in to help on that question, since the assumption is, you've been helped.  If the Proposed Answer helped you, please accept it and award that expert.  If it did not help you, please reject it and add comments as to status and what else is needed.
 
If you wish to award multiple experts, just comment here with detail, I'll respond as soon as possible.  As it stands today, you asked the question, got help and not one expert was awarded for the contribution(s) made.  Your response is needed.  I'll monitor through month end, and if you've not returned to complete this, we'll need to decide.  Expert input is welcome (as always) to determine the outcome here if the Asker does not respond.
 
Your response in finalizing this (and ALL) your question(s) is appreciated.
 
Moondancer
Community Support Moderator @ Experts Exchange

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now