差不多两个星期前,我创建了类似的关于上传使用的问题OneupUploaderBundle,但是使用了FineUploader库.可悲的是,还没有答案.在此期间,我尝试设置不同的上传库.
我开发上Windows 10 Pro与XAMPP[1],其包括PHP v7.0.8.
我正在使用Symfony v3.1.5,OneupUploaderBundle和Blueimp jQuery上传,以便将文件上传到服务器.
在设置时,我遵循了OneUpUploaderBundle[2]和jQuery file upload[3],[4]的文档.
我想将文件上传到某个目录,然后检查他们的mime类型并验证是否允许上传文件mime类型,之后 - 将它们移动到自定义目录(可以从文件更改为文件),最后我想保留文件路径和文件名到数据库.
文件上传工作正常,文件上传到oneup_uploader_endpoint('gallery').即使是自定义文件Namer也可以上传到自定义目录.
但是,不会调用侦听器(上传侦听器和验证)并显示在Symfony Profiler Events部分中Not Called Listeners!
这是不幸的,因为我想使用Post_Persist事件将有关文件的信息保存到数据库.OneupUploaderBundle事件.
我的services.yml
services:
app.upload_listener:
class: AppBundle\EventListener\UploadListener
arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: kernel.event_listener, …Run Code Online (Sandbox Code Playgroud) 为了将多个文件上传到我正在使用的服务器:
jQuery UI Widget版本请注意:此配置适用于单个和多个文件上传,但在抛出时不会返回任何内容!responseValidationException
为了知道文件的上传成功完成,我添加了部分响应UploadListener:
public function onUpload(PreUploadEvent $event)
{
$file = $event->getFile();
$response = $event->getResponse();
$message = [
'error' => 'none'
];
$response->addToOffset($message, array('files'));
}
Run Code Online (Sandbox Code Playgroud)
它给出了以下响应(如果文件上传没有错误)
response: {"files":[{"error": "none"}]}
Run Code Online (Sandbox Code Playgroud)
我想response在ValidationException抛出时收到相应的错误.
例:
response: {"files":[{"error": "error code"}]}
Run Code Online (Sandbox Code Playgroud)
我使用验证器来限制一些可上传的文件.
目前 - 没有上传(正在抛出)validator限制的文件.然而,在这种情况下没有发送到客户端/浏览器!ValidationExceptionresponse
我不知道如何在客户端/浏览器之后制作Plupload并Symfony3返回错误ValidationException.
验证监听器:
<?php
namespace …Run Code Online (Sandbox Code Playgroud) 为了将多个文件上传到我正在使用的服务器:
请注意:
jQuery File Upload示例Basic Plus UI用户界面.(另外,我没有在互联网上找到任何相关的例子).upload progress bar(所有文件通用)和upload button(上传所有添加的文件)所以几乎没有UI!我想创建多个文件上传,这将接近于jQuery File Upload示例Basic Plus UI,但是:
目前至少没有办法确定哪个文件出错了!
例如:我从服务器获得以下JSON响应
data.jqXHR.responseText = {"files":[{"error":"error.maxsize"},{"error":"error.maxsize"}]}
Run Code Online (Sandbox Code Playgroud)
但当时有3个上传的文件 - 所以 - 没有信息哪个错误对应哪个文件!
如果我像这样修改上传监听器:
public function onUpload(PreUploadEvent $event)
{
$file = $event->getFile();
$response = $event->getResponse();
$response['files'] = [
'name'=> $file->getBaseName(),
'type'=> $file->getType(),
'size'=> $file->getSize(),
];
return json_encode($response);
} …Run Code Online (Sandbox Code Playgroud) 我正在一个需要文件上传的项目上尝试Symfony 4.1++ 。为此,我选择使用前端。YarnWebpack EncoreOneUpUploaderBundleBlueimp jquery file upload
但是,与旧式的酷方法相比,需要添加大量的配置CSS并JavaScript
在需要的地方添加它们,但缺乏包管理的优势,这让其受到了一些困扰。
当然,使用包管理器轻松更新依赖项确实需要付出代价。但是,在初始配置构建编译之后,之后很容易或者应该很容易。
我希望能够使用前面提到的库组合上传文件。我正在寻找正确的配置。
目前构建无法编译 - 我收到错误!
ERROR Failed to compile with 1 errors
This dependency was not found:
* jquery-ui/ui/widget in ./node_modules/blueimp-file-upload/js/jquery.fileupload.js
Run Code Online (Sandbox Code Playgroud)
正如您从附加代码中看到的那样,我尝试为 提供别名jquery-ui/ui/widget,但它没有找到找到的包。
另外,Yarn 目录中没有包jquery-ui/ui/widget,但jquery.ui.widget我尝试要求但未成功。
Webpack.config.js
var Encore = require('@symfony/webpack-encore');
const CopyWebpackPlugin = require('copy-webpack-plugin');
Encore
// directory where all compiled assets will be stored
.setOutputPath('public/build/')
// what's the public path to this …Run Code Online (Sandbox Code Playgroud) 在我使用的个人项目中:
我想成功地从控制器运行CravlerMaxMindGeoIpBundle's命令php bin/console cravler:maxmind:geoip-update.
目前我已经设置了CravlerMaxMindGeoIpBundlebundle和命令php bin/console cravler:maxmind:geoip-update在命令行中正常工作.
然后我按照官方文档(介绍部分的第4个链接).当然改变了可调用的命令.然而我收到了一个错误.
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "cravler:maxmind" namespace.
Run Code Online (Sandbox Code Playgroud)
如何在没有错误的情况下运行命令该怎么办?
我在控制器中的动作
public function geoIpUpdateAction(Request $request)
{
$kernel = $this->get('kernel');
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput(array(
'command' => 'cravler:maxmind:geoip-update'
));
// You can use NullOutput() if you don't need the output
$output = new BufferedOutput();
$application->run($input, $output); …Run Code Online (Sandbox Code Playgroud) 我需要为多语言词典设计数据库。
我在 SO 中查看了类似的问题,但结果证明这是一个更简单的案例,并不真正适用。
我的想法是这样的:
table: languages (id, name)
1, English
2, French
table: words (id, lang_id, word)
1, 1, cat
2, 1, pussy cat
3, 1, kitten
4, 1, puss
5, 2, le chat
6, 2, le felin
table: synonyms (id, word_id, word_id)
1, 1, 2
2, 1, 3
3, 1, 4
4, 5, 6
table: translations (id, word_id, word_id)
1, 1, 5
2, 2, 5
3, 3, 5 …Run Code Online (Sandbox Code Playgroud) php ×4
symfony ×4
blueimp ×2
command-line ×1
database ×1
dictionary ×1
file-upload ×1
javascript ×1
jquery ×1
mysql ×1
plupload ×1
sql ×1
symfony4 ×1
webpack ×1
yarnpkg ×1