Solved

TEXTAREA submission limit

Posted on 2001-06-20
8
429 Views
Last Modified: 2008-03-04
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
Comment
Question by:webhermit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:higijj
ID: 6212297
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6212438
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
 
LVL 7

Accepted Solution

by:
daniel_c earned 100 total points
ID: 6212439
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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 1

Author Comment

by:webhermit
ID: 6212444
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
 

Expert Comment

by:meetyg
ID: 6214536
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
 
LVL 2

Expert Comment

by:higijj
ID: 6224323
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
 
LVL 2

Expert Comment

by:higijj
ID: 6224324
webhermit, feel free to reject the above answer ..
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6419386
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question