OneupUploaderBundle:文件没有上传,为什么?

时间:2014-11-28 16:35:23

标签: php jquery symfony oneupuploaderbundle

我尝试使用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包中使用了相同的文件夹并且上传了这些文件,因此权限可能不是问题,有什么想法吗?

修改

我按here写了一个die('meep')并且响应返回了死但文件仍未上传,对此有何建议?

2 个答案:

答案 0 :(得分:1)

第一

如果您是第一次运行此捆绑包,则所有人都会经常出错:检查您的文件夹web是否可写 ...

第二

尝试让捆绑包的配置简单如下:

oneup_uploader:
    mappings:
        recaudos:
            frontend: blueimp 
            enable_progress: true 

答案 1 :(得分:0)

快速检查您的代码,我发现您的javascript代码中缺少#

$(document).ready(function(){
    $('#fileUpload3').fileupload(); // the missing # is here
});