我正在实施精细上传器。这就是我所做的:
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"
}
});
}
fineupload.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权限。
答案 0 :(得分:0)
就这个特定问题而言,您的PHP文件无关紧要。如果您不想使用Fine Uploader的默认样式“选择文件”按钮,则必须在您的自定义“按钮”元素上指向Fine Uploader。
在您的情况下,您需要添加button
选项,如下所示:
button: document.getElementById('#fine-uploader-basic')