简体   繁体   中英

Converting a Text Area to a File (HTML JQuery AJAX PHP)

I have a question that might have another answer than what I'm thinking of doing.

So, I have a text area that is populated by a DB. I'm allowing the users use it as a notepad and whatnot.

Some of these notes can get pretty big and potentially exceed the URL Character limit. I also have to encode (I'm using encodeURIComponent ) the strings which cuts into the amount of characters too.

I thought the best way would be to convert the text area into a file and then post the file towards my handler php file where it gets uploaded into the db and whatnot. I'm not certain how to do this with JQuery/Javascript or if there was another way to handle this.

Thanks in advance!

-- Table Code --

echo "<table class='content' id='quick-notes-list'>
    <tr style='border-bottom:2pt solid #DFEFFC'>
        <td colspan='2'>Note Name</td>
        <td>Last Updated</td>
    </tr>";
    $i = 0;
    while ( $Notes = mysql_fetch_array($getNotes) )
    {
        $style = ( $i % 2 ? 'ui-state-default row' : 'altrow row'); $i++;

        $noteDate = date("M, d Y", strtotime($Notes['updated']));
        $noteTime = date("g:i a", strtotime($Notes['updated']));

        echo "
        <tr class='noteName' onMouseOver=\"this.className='ui-widget-header row'\" onMouseOut=\"this.className='$style'\" >
            <td valign='top'>
                <a href='{$Notes['note_id']}'></a>
                <b>{$Notes['note_name']}</b>
                <br />
                <i id='summary{$Notes['note_id']}'>" . substr($Notes['note_body'], 0, 150) . "...</i>
            </td>
            <td width='160' valign='top'>" . str_replace(" ", "&nbsp;", $Contact['name']) . "</td>
            <td width='120' valign='top'>
                <i>" . str_replace(" ", "&nbsp;", " {$noteDate} - {$noteTime}") . "</i>
            </td>
        </tr>
        <tr id='note{$Notes['note_id']}' style='display: none' onMouseOver=\"this.className='ui-widget-header row'\" onMouseOut=\"this.className='$style'\">
            <td colspan='2'>
                <textarea id='note-body-{$Notes['note_id']}'>{$Notes['note_body']}</textarea>
            </td>
            <td style='text-align: right;'>
                <button id='saveNote' value='{$Notes['note_id']}' class='ui-state-focus'>Save</button>
                <button id='deleteNote' value='{$Notes['note_id']}' class='ui-state-focus'>Delete</button>
            </td>
        </tr>
        ";
    }

-- AJAX Function Below --

$('#saveNote').click(function() {
            noteID = $(this).attr('value');
            newText = encodeURIComponent($('#note-body-' + noteID).val());

            $.ajax({
                url     : "manage-save-quick-notes.php",
                type    : "POST",
                data    : data,
                success: function(data, textStatus, jqXHR)
                {
                    //data - response from server
                },
                error: function (jqXHR, textStatus, errorThrown)
                {

                }
            });
  • It's probably not a good idea to have file upload where you don't really need. It will be just a security concern
  • If you are sending the data through a POST request, the size won't actually be a problem since it's limit is set Server side, on your Apache configs.

To increase the limit POST size limit: Increasing the maximum post size

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM