我正在尝试使用 OneupUploaderBundle 上传文件,几乎所有文件都在工作,但文件没有上传,我找不到问题所在。这是我的UploadLister
样子:
namespace AppBundle\EventListener;
use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\Event\PreUploadEvent;
use AppBundle\Entity;
class UploadListener
{
protected $doctrine;
protected $originalName;
protected $tipoRecaudo3;
protected $tipoRecaudo4;
protected $tipoRecaudo5;
public function __construct($doctrine)
{
$this->doctrine = $doctrine;
}
public function onUpload(PreUploadEvent $event)
{
$file = $event->getFile();
$response = $event->getResponse();
$this->originalName = $file->getClientOriginalName();
$this->tipoRecaudo3 = $event->getRequest()->get('tipoRecaudo3', null);
$this->tipoRecaudo4 = $event->getRequest()->get('tipoRecaudo4', null);
$this->tipoRecaudo5 = $event->getRequest()->get('tipoRecaudo5', null);
$url = "";
$deleteUrl = "";
$response['files'] = [
'name' => $file->getClientOriginalName(),
'size' => $file->getSize(),
'url' => $url,
'deleteUrl' => $deleteUrl,
'deleteType' => 'DELETE'
];
}
public function onPostUpload(PostUploadEvent $event)
{
$em = $this->doctrine->getManager();
$request = $event->getRequest();
$productoSolicitud = $em->getRepository('AppBundle:ProductoSolicitud')->find($request->getSession()->get('productoSolicitudId'));
$recaudosTramiteProductoSolicitud = new Entity\RecaudosTramitesProductoSolicitud();
$recaudosTramiteProductoSolicitud->setProductoSolicitud($productoSolicitud);
$recaudosTramiteProductoSolicitud->setArchivo($this->originalName);
if ($this->tipoRecaudo3 !== null)
{
$recaudosTramiteId = $this->tipoRecaudo3;
} else if ($this->tipoRecaudo4 !== null)
{
$recaudosTramiteId = $this->tipoRecaudo4;
} elseif ($this->tipoRecaudo5 !== null)
{
$recaudosTramiteId = $this->tipoRecaudo5;
}
$recadudoTramite = $em->getRepository('AppBundle:RecaudosTramite')->find($recaudosTramiteId);
$recaudosTramiteProductoSolicitud->setRecaudosTramite($recadudoTramite);
$em->persist($recaudosTramiteProductoSolicitud);
$em->flush();
}
}
并且它有效,因为实体被持久化到 BD。现在这就是我的捆绑配置的外观config.yml
:
oneup_uploader:
mappings:
recaudos:
frontend: blueimp
storage:
service: ~
type: filesystem
filesystem: ~
directory: %kernel.root_dir%/../web/uploads/recaudos
stream_wrapper: ~
allowed_mimetypes: [application/msword,image/jpeg,image/pjpeg,image/png,application/pdf,application/vnd.oasis.opendocument.text]
error_handler: oneup_uploader.error_handler.noop
use_orphanage: true
enable_progress: true
enable_cancelation: true
namer: oneup_uploader.namer.uniqid
在 Twig 模板级别,这就是我所拥有的:
<form id="cargaRecaudos3" action="" method="POST" enctype="multipart/form-data" class="form-horizontal" role="form">
<input id="fileUpload3" class="fileUpload" type="file" name="fileUpload3[]" data-url="{{ oneup_uploader_endpoint('recaudos') }}" multiple />
</form>
当然,组件是在 jQuery 级别初始化的:
$(document).ready(function(){
$('#fileUpload3').fileupload();
});
任何想法为什么不上传文件?我正在使用 VichUploader 包中的相同文件夹,并且这些文件已上传,因此权限可能不是问题,有什么想法吗?
编辑
我在这里写了一个,响应返回了 die 但文件仍然没有上传,对此有什么建议吗die('meep')
?