dtncv04228 2014-05-10 13:35
浏览 59
已采纳

如何使Fine Uploader不忽略文本区域?

I've learned to use Fine Uploader with forms. However, I can't make Fine Uploader not to ignore textareas in forms. The JS library will pass input field data on to PHP endpoint but won't do anything with textareas.

Here's a live demo: http://www.digioppikirja.fi/v3/fineuploader2.html

If you fill the form and take a look at the contents of $_REQUEST, you'll see everything but the textarea contents: http://www.digioppikirja.fi/v3/dump_textarea.txt

What to do?

HTML:

<html>
<head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="http://www.digioppikirja.fi/v3/custom.fineuploader-4.4.0/custom.fineuploader-4.4.0.min.js"></script>
    <link href="fineuploader.css">
    <script type="text/template" id="qq-template">
        <div class="qq-uploader-selector qq-uploader">
            <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
                <span>Drop files here to upload</span>
            </div>
            <div class="qq-upload-button-selector qq-upload-button">
                <div>Select Files</div>
            </div>
            <span class="qq-drop-processing-selector qq-drop-processing">
                <span>Processing dropped files...</span>
                <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
            </span>
            <ul class="qq-upload-list-selector qq-upload-list">
                <li>
                    <div class="qq-progress-bar-container-selector">
                        <div class="qq-progress-bar-selector qq-progress-bar"></div>
                    </div>
                    <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
                    <span class="qq-upload-file-selector qq-upload-file"></span>
                    <span class="qq-upload-size-selector qq-upload-size"></span>
                    <a class="qq-upload-cancel-selector qq-upload-cancel" href="#">Cancel</a>
                    <span class="qq-upload-status-text-selector qq-upload-status-text"></span>
                </li>
            </ul>
        </div>
    </script>
<head>

<body>
    <form action="endpoint2.php" method="post" enctype="multipart/form-data" id="qq-form">
        <label>Enter your name</label>
        <input type="text" name="user_name" required>
        <label>Enter your email</label>
        <input type="email" name="user_email" required>
        <br /><br />
        <label>The very best thing in travelling</label><br />
        <textarea cols="50" rows="10" name="travelling"></textarea>
        <input type="submit" value="Done">
    </form>

    <div id="my-uploader"></div>

    <script>
        $("#my-uploader").fineUploader();
    </script>
</body>

PHP:

    require_once "handler.php";
require_once "../cfg/digikirjat.cfg.php";

$uploader = new UploadHandler();

// Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp")
$uploader->allowedExtensions = array(); // all files types allowed by default

// Specify max file size in bytes.
$uploader->sizeLimit = 10 * 1024 * 1024; // default is 10 MiB

// Specify the input name set in the javascript.
$uploader->inputName = "qqfile"; // matches Fine Uploader's default inputName value by default

// If you want to use the chunking/resume feature, specify the folder to temporarily save parts.
$uploader->chunksFolder = "chunks";

$method = $_SERVER["REQUEST_METHOD"];
if ($method == "POST") {
    header("Content-Type: text/plain");

    // Call handleUpload() with the name of the folder, relative to PHP's getcwd()
    $result = $uploader->handleUpload($_dirs['temp'].'/upload/');

    // To return a name used for uploaded file you can use the following line.
    $result["uploadName"] = $uploader->getUploadName();


    echo json_encode($result);

    $a = print_r($_REQUEST, true);
    file_put_contents(getcwd().'/dump_textarea.txt', $a);

}
else {
    header("HTTP/1.0 405 Method Not Allowed");
}
  • 写回答

1条回答 默认 最新

  • douchigu1723 2014-05-10 14:34
    关注

    Looks like the form field parser isn't currently handling <textarea> elements. I've opened up a case and will fix that as part of Fine Uploader 5.0.

    Until that is fixed, you can easily work around this issue by parsing the <textarea> in an onUploader (or any other desired) callback handler and adding it as a parameter via setParams. For example:

    callbacks: {
        onUpload: function(id) {
            var textAreaContent = document.getElementsByName("travelling")[0].value;
            this.setParams({travelling: textAreaContent}, id);
        }
    }
    

    NOTE: I haven't tested the above code, let me know if you are having any issues with it, but it should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的