0

我正在实施良好的上传器。这是我所做的:

1) 我添加了以下 html 和 js 类:

 <link rel="stylesheet" href="Content/fineuploader-3.4.1.css" /> 
<script type="text/javascript" src="Scripts/jquery.fineuploader-3.4.1.min.js"></script>

HTML

<input type="text" class="input-medium" placeholder="Document Type" data-bind="value: type"/>
                                   <div id="fine-uploader-basic" class="btn btn-success" data-bind="click:$root.uploadFile">
                                        <i class="icon-upload icon-white"></i> Click to upload
                                    </div>
                                    <div id="messages"></div>

JS文件

uploadFile: function(data) { 
       var uploader = new qq.FineUploader({
        element: $('#fine-uploader')[0],
        debug: true,
        request: {
            endpoint: "php/fileupload.php"
        }
    });
    }

精细上传.php 文件:

<?php
$file = $_FILES['qqfile'];
$uploadDirectory = 'uploads';
$target = $uploadDirectory.DIRECTORY_SEPARATOR.$file['files.php'];
$result = null;
if (move_uploaded_file($file['tmp_name'], $target)){
    $result = array('success'=> true);
    $result['uploadName'] = $file['name'];
} else {
    $result = array('error'=> 'Upload failed');
}
header("Content-Type: text/plain");
echo json_encode($result);

?>

files.php(存储文件的位置)

<?php 

// Include the uploader class
require_once 'php/fileupload.php';

$uploader = new qqFileUploader();

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

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

// Specify the input name set in the javascript.
$uploader->inputName = 'qqfile';

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

// Call handleUpload() with the name of the folder, relative to PHP's getcwd()
$result = $uploader->handleUpload('uploads');

// To save the upload with a specified name, set the second parameter.
// $result = $uploader->handleUpload('uploads/', md5(mt_rand()).'_'.$uploader->getName());

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

header("Content-Type: text/plain");
echo json_encode($result);
?>

问题:

当我单击该按钮时,它会更改为以下内容: 在此处输入图像描述

绿色按钮内的那个红色按钮应该与绿色按钮分开。

而且,选择文件的弹出窗口也不会出现。两个 PHP 文件都有 777 权限。

4

1 回答 1

0

就这个特定问题而言,您的 PHP 文件是无关紧要的。如果您不想使用 Fine Uploader 的默认样式“选择文件”按钮,则必须将 Fine Uploader 指向您的自定义“按钮”元素。

在您的情况下,您需要添加button如下选项:
button: document.getElementById('#fine-uploader-basic')

于 2013-04-07T17:01:04.423 回答