PHP Jquery文件上载//用户名/会话目录
我在PHP上玩了几周Blueimp的Jquery文件上传,遇到了一些问题。我正在教自己如何用PHP编程,所以我仍然习惯于事情的运作方式,因此,对于任何困惑,我深表歉意,我将尽力澄清 我需要将用户上传插入上传目标目录中的特定用户名文件夹。我已经遵循了大量的书写、答案和常见问题解答来打开上述用户目录(对于这个插件),并且最多为会话创建一个文件夹,其中包含一个misc字符串。字符,但无论用户名如何,所有上载都将转到同一文件夹,而不是用户各自的文件夹。是否可以告诉脚本读取并使用特定用户名/id/etc作为变量?我很确定是这样,但目前我找不到一个明确的方法。为了清晰起见,我尝试将我的代码保持为基本的,并与发布的Blueimp版本相似 好了,开始吧 **工作:**用户注册,信息插入数据库,在上传目录中自动创建相应的用户名文件夹,并耐心等待用美味的文件填充PHP Jquery文件上载//用户名/会话目录,php,session,file-upload,jquery-file-upload,blueimp,Php,Session,File Upload,Jquery File Upload,Blueimp,我在PHP上玩了几周Blueimp的Jquery文件上传,遇到了一些问题。我正在教自己如何用PHP编程,所以我仍然习惯于事情的运作方式,因此,对于任何困惑,我深表歉意,我将尽力澄清 我需要将用户上传插入上传目标目录中的特定用户名文件夹。我已经遵循了大量的书写、答案和常见问题解答来打开上述用户目录(对于这个插件),并且最多为会话创建一个文件夹,其中包含一个misc字符串。字符,但无论用户名如何,所有上载都将转到同一文件夹,而不是用户各自的文件夹。是否可以告诉脚本读取并使用特定用户名/id/etc作
**不工作:*上载脚本未读取要用作目标文件夹名称的用户名/变量。执行时,“Error SyntaxError:Unexpected token您需要编辑index.php以设置
$username
变量
将代码更新为:
require('UploadHandler.php');
$upload_handler = new UploadHandler($username);
在UploadHandler.php文件中,将\u构造更新为:
function __construct($username, $options = null, $initialize = true, $error_messages = null) {
现在,它应该捕获传递的$username
。您可以尝试还原原始服务器/php/UploadHandler.php,然后在wiki中阅读本文:
要提供自己的实现,可以重写get\u user\u id方法
编辑index.php:
<?php
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
class CustomUploadHandler extends UploadHandler {
protected function get_user_id() {
return $_REQUEST['username'];
}
protected function set_additional_file_properties($file) {
$file->deleteUrl = $this->options['script_url']
.$this->get_query_separator($this->options['script_url'])
.$this->get_singular_param_name()
.'='.rawurlencode($file->name)
.'&username='.$_REQUEST['username']
;
$file->deleteType = $this->options['delete_type'];
if ($file->deleteType !== 'DELETE') {
$file->deleteUrl .= '&_method=DELETE';
}
if ($this->options['access_control_allow_credentials']) {
$file->deleteWithCredentials = true;
}
}
}
$upload_handler = new CustomUploadHandler(array(
'user_dirs' => true,
));
您是否尝试在官方blueimp论坛上发布?文档建议在此处发布,因为没有官方支持渠道。感谢您的输入。我更新了代码,但它仍然返回相同的错误并上载到父/上载/文件夹。仍在调整以查看是否可以使其正常工作。我尝试的是让脚本阅读来自数据库或会话的用户名,但我只是无法建立连接。
function __construct($username, $options = null, $initialize = true, $error_messages = null) {
<?php
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
class CustomUploadHandler extends UploadHandler {
protected function get_user_id() {
return $_REQUEST['username'];
}
protected function set_additional_file_properties($file) {
$file->deleteUrl = $this->options['script_url']
.$this->get_query_separator($this->options['script_url'])
.$this->get_singular_param_name()
.'='.rawurlencode($file->name)
.'&username='.$_REQUEST['username']
;
$file->deleteType = $this->options['delete_type'];
if ($file->deleteType !== 'DELETE') {
$file->deleteUrl .= '&_method=DELETE';
}
if ($this->options['access_control_allow_credentials']) {
$file->deleteWithCredentials = true;
}
}
}
$upload_handler = new CustomUploadHandler(array(
'user_dirs' => true,
));
$(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: 'server/php/index.php?username=' + username,
});
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(
/\/[^\/]*$/,
'/cors/result.html?%s'
)
);
// Load existing files:
$('#fileupload').addClass('fileupload-processing');
$.ajax({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: $('#fileupload').fileupload('option', 'url'),
dataType: 'json',
context: $('#fileupload')[0]
}).always(function () {
$(this).removeClass('fileupload-processing');
}).done(function (result) {
$(this).fileupload('option', 'done')
.call(this, $.Event('done'), {result: result});
});
});
}