title: Laravel 5 safe upload document files
body: <p>in this case I want to safe upload <code>pdf, doc, docx, ppt, pptx, xls, xlsx, rar, zip</code> prevent from arbitrary file upload especially web shell or any evil script.</p>
  
  <p>The problem is how I can validate file, is safe to upload? prevent from bypass like change mime type with tamper data, rename file with multiple extension, using <code>;</code> and space in file name, lowercase and uppercase file extension and etc.</p>
  
  <p>my controller code look like this</p>
  
  <pre><code>public function fileUpload(){
      $ext = ['pdf', 'doc', 'ppt', 'xls', 'docx', 'pptx', 'xlsx', 'rar', 'zip'];
      $data = Request::all();
      $name = $data['file']-&gt;getClientOriginalName();
      $rules = [
          'file' =&gt; 'required'
      ];
      $v = Validator::make($data, $rules);
      if($v-&gt;passes()){
          // Check safe file validation
          // should here or something? and how to prevent bypass
          // arbitrary file upload especially evil script.
          $data['file']-&gt;move(public_path('assets/uploads'), $name);
          return 'file uploaded';
      }else{
          return 'file upload failed';
      }
  </code></pre>
  
  <p>}</p>