2014-02-09 2 views
2

내 웹 사이트에 dropzonejs 파일 업로드를 구현하기 위해 노력하고있어,하지만 난이 오류DROPZONE 및 비 개체 오류

{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to a member function isValid() on a non-object","file":"C:\\Users\\Username\\Desktop\\localhost\\Project\\app\\controllers\\FileController.php","line":147}} 

받고 있어요 나는 머리 태그 안에이 있습니다. 파일이 Image인지 확인한 다음 파일을 컨트롤러로 보내기 전에 크기를 확인합니다. 파일이 이미지가 아니라면 컨트롤러로 바로 보내십시오.

<script type="text/javascript"> 
    $(function() { 
    Dropzone.options.createFile = { 
     accept: function(file, done) { 
     // checking if the filetype is an image to check the dimensions 
     if ((/\.(gif|jpg|jpeg|tiff|png)$/i).test(file.name)) {    
      var pixels = 0; 
      var reader = new FileReader(); 
      reader.onload = (function(file) { 
      var image = new Image(); 
      image.src = file.target.result; 
      image.onload = function() { 
      width = this.width; 
      height = this.height; 
      if(width < 800 || height < 300) { 
       done('image is not 800x300 pixels!'); 
      } else { 
       done(); 
      } 
      }; 
      }); 
      reader.readAsDataURL(file);    
     } else { 
      // if the file is not an image 
      done(); 
     } 
     }, 
     url: '/process/create-file', 
     previewsContainer: ".dropzone-previews", 
     uploadMultiple: true, 
     parallelUploads: 100, 
     maxFiles: 100, 
    } 
    }); 
</script> 

이것은 박탈 된 컨트롤러입니다. 오류가 바로 위에 있기 때문에. 나는 $file->isValid() 줄 앞에 return var_dump($file)을 추가하는 경우

public function postCreateFile() 
{ 
    if(!Input::hasFile('file')) 
    return Response::json('Where is the file?', 400); 

    $file = Input::file('file'); 
    if($file->isValid()){ 
     // do stuff 
    } 
} 

나는이 응답을

array (size=2) '_token' => string 'BtN7aFkEUQvXlaJDzxx28e4WMI08h5bl3VqrEaHR' (length=40) 'file' =>  array (size=1)  0 =>   object(Symfony\Component\HttpFoundation\File\UploadedFile)[9]   private 'test' => boolean false   private 'originalName' => string '65VWl.jpg' (length=9)   private 'mimeType' => string 'image/jpeg' (length=10)   private 'size' => int 260740   private 'error' => int 0 

을 얻을 그리고 여기 형태이다. enctype 및 파일을 true로 설정했지만 위의 설명과 같이 "non-object"라는 메시지가 계속 표시됩니다.

{{ Form::open(array('class' => 'dropzone', 'id' => 'create-file', 'url' => 'process/create-file', 'enctype' => 'multipart/form-data', 'files' => true)) }} 
    <div class="dropzone-previews" id="giga-drop"> 
     <div class="fallback"> 
     {{ Form::file('file') }} 
     </div> 
    </div> 
{{ Form::close() }} 

왜 이런 오류가 발생합니까?

+1

'$ file'에 의해 볼 때 배열 (인을' var_dump' 출력) 객체에 대한 메소드를 호출하려고합니다. 오류가 있습니다. – Maerlyn

+0

어떻게 해결할 수 있습니까? –

+0

절대로 laravel을 사용하지 않았습니다. 문서에있는 것 같습니다. – Maerlyn

답변

2

@Maerlyn이 어레이 였음을 알려 주셔서 감사합니다. 또한 나는이 내 $ 파일 변수를 수정했다 Laravel and Dropzonejs, files are not uploaded correctly

전에 검색 할 때 내가 알아 차리지 않았다 링크 발견 :

$file = Input::file('file'); // didn't work 
$file = Input::file('file')[0]; // works 
+0

만약 내가 이것을 다시 upvote 수 있습니다. :) –

관련 문제