Laravel和Dropzonejs,文件未正确上传 [英] Laravel and Dropzonejs, files are not uploaded correctly

查看:91
本文介绍了Laravel和Dropzonejs,文件未正确上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个涉及文件上传的项目。我正在使用DropzoneJS和Laravel来完成这个项目。一切似乎工作正常,我已正确包含js和css文件,也显示在示例中的形式,但问题是上传部分! Droped文件显示进度条转到100%,但一旦达到它就会返回如下错误...

I ham working on a project which involves file uploading. I am using DropzoneJS and Laravel for this project. Everything seems to work fine, i have included the js and css files correctly, also the form appears as in the example but the problem is the upload part! Droped files show the progress bar go to 100% but once reached it returns an error like this...

{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to a member function getClientOriginalName() on a non-object","file":"C:\\wamp\\www\\localsite\\app\\controllers\\AssetsController.php","line":121}}

我知道当我返回var_dump(输入::)时上传过程无效file('file)); 我得到一个输入数据数组......

I know that the upload process works ine becouse when i return var_dump(Input::file('file)); i get an array of the input data...

..但......

..but...

当我检查这样的文件输入:: hasFile('photo')时,似乎该文件是emty但它有一个数组表格。

When i check for file like this Input::hasFile('photo') it seems that file is emty but it has an array form.

这是路线

Route::post('create/album','AssetsController@album');

这是控制器

public function album()
{

    $file = Input::file('file');

    $destinationPath = 'uploads';
    $filename = $file->getClientOriginalName();

    $uploadSuccsess = Input::file('file')->move($destinationPath, $filename);


       if( $uploadSuccsess ) {
         return Response::json('success', 200);
       } else {
         return Response::json('error', 400);
       }

}

这是HTML

     <form action="http://localhost/create/album" enctype="multipart/form-data" id="post-form-dropzone" class="dropzone">
     </form>
<button type="submit" id="status-post-form-submit-btn" class="btn btn-sm btn-primary btn-post pull-right">Post</button>

这是JS

Dropzone.options.PostFormDropzone = { // The camelized version of the ID of the form element

  acceptedFiles: "image/*", // Accept images only
  autoProcessQueue: false,
  uploadMultiple: true,
  parallelUploads: 100,
  maxFiles: 60,
  addRemoveLinks: true,

  // The setting up of the dropzone
  init: function() {
    var myDropzone = this;
    // First change the button to actually tell Dropzone to process the queue.
    $("#status-post-form-submit-btn").click(function(e) {

      e.preventDefault();
      e.stopPropagation();
      myDropzone.processQueue();
    });


  }

}

我已经尝试了几个小时,但我似乎无法找到解决方案。

Ive been trying for hours but i cant seem to find the solution.

提前致谢。

推荐答案

终于想出了如何解决这个问题,这就解决了这个问题,这是我改变的控制器

finally figured out how to fix this, this is what got it fixed this is my changed Controller

$file = Input::file('file');
    Image::make($file[0]->getRealPath())->resize(540, null, true)->save('assets/example.png');

如果有人问这些图像处理方法来自哪里,那么使用 http://intervention.olivervogel.net/image/getting_started/laravel

If anyone is asking where did those image manipulation methods came from this is the class iam using http://intervention.olivervogel.net/image/getting_started/laravel

希望这可以帮助未来的人

Hope this helps someone in the fututre

这篇关于Laravel和Dropzonejs,文件未正确上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆