2

I am trying to upload file based on this answer:

<form enctype="multipart/form-data" action="http://localhost:61113/api/file/upload" method="post">
   <div>
          <input type="text" placeholder="No file selected" id="txtPath" />
          <div id="div-btn">
             Choose File
             <input type="file" class="hide_file" id="browse-btn">
           </div>
    </div>
    <button id="btnScan" type="submit">Scan</button>
</form>

but in the server side I only get at the content of the request:

------WebKitFormBoundaryYhhj0sW5ARh7d9ZO--

and I cant see the file's content, I meen it seems like it doesn't sends the file, what am I missing?

Codey
  • 487
  • 1
  • 8
  • 27

3 Answers3

2

You're missing the name attribute

<input type="file" class="hide_file" id="browse-btn" name="file">
Vindur
  • 364
  • 3
  • 12
1

You need to insert also the attribute name for the input file.

Than get the file data through $_FILES; the value of the name attribute will be a key in the $_FILES array.

For example:

<input type="file" class="hide_file" id="browse-btn" name='fileUploaded'>

in the server side:

$fileData = $_FILES['fileUploaded'];
user2342558
  • 5,567
  • 5
  • 33
  • 54
1

First of all are you using AJAX? If so, there is no need for name attribute. You can get file with id attribute, but if not so you must use name attribute.

a.akkus
  • 73
  • 1
  • 11