-1

I'm currently doing some web development work and my assignment requires me to upload a file to a server. I have the following code:

<form id = "uploadbanner" method = "post">
     <input id = "fileupload" type = "file" />
</form>

I don't have a submit button, since there's already one at the bottom of the page. Whenever I test out the code and input a file x, it tells me that it cannot find x. I've tried seeing if I could obtain the path name from the client to see if this was the issue, but that isn't allowed due to security reasons. Any help would be appreciated; thanks!

Huy Vo
  • 2,171
  • 5
  • 23
  • 39
  • add **action="yoururl.php"** to your form. – Denny Sutedja Nov 11 '16 at 01:29
  • _"it tells me that **it** cannot find x"_ — what is **"it"?** Is that something you see in the browser's javascript console? Is that the result of trying to find the file on the webserver? When you `POST` a form to the server, the server has to actually do something to save the file. Denny and Huy are both assuming you are using PHP on the server ... are you? If you just have a `.html` file that you are opening without using a web server this will never work. – Stephen P Nov 11 '16 at 01:38

2 Answers2

2

This could help:

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload File" name="submit">
</form>
Huy Vo
  • 2,171
  • 5
  • 23
  • 39
0

In order to achieve the upload, you must:

Don't forget to link your submit button to the form and you're good to go.

Community
  • 1
  • 1
joaomlap
  • 89
  • 9