簡體   English   中英

將文本區域轉換為文件(HTML JQuery AJAX PHP)

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

我有一個問題可能比我正在考慮的問題有另一個答案。

因此,我有一個由DB填充的文本區域。 我允許用戶將其用作記事本等。

其中一些注釋可能會變得很大,甚至可能超出URL字符限制。 我還必須編碼(我正在使用encodeURIComponent)也切入字符數量的字符串。

我認為最好的方法是將文本區域轉換為文件,然后將文件發布到我的處理程序php文件中,在該文件中將其上傳到db中,什么都不會。 我不確定如何使用JQuery / Javascript來執行此操作,或者不確定是否可以使用另一種方法來執行此操作。

提前致謝!

-表格代碼-

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功能-

$('#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)
                {

                }
            });
  • 在您真正不需要的地方上傳文件可能不是一個好主意。 這只是安全問題
  • 如果您通過POST請求發送數據,則大小實際上不會成為問題,因為它的限制是在Apache配置上設置為服務器端。

要增加POST大小限制,請執行以下操作: 增加最大POST大小

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM