55

Basically, I have this form that allows user to upload to my server:

<form id = "uploadbanner" method = "post" action = "#"> <input id = "fileupload" type = "file" /> <input type = "submit" value = "submit" id = "submit" /> </form> 

But the problem is that when I choose a file, then click submit, I don't see the file uploaded in the server directory.

2
  • 8
    HTML can only select and send the file content. It's the server's responsibility to get the file content. HTML doesn't run in the server. Only server side languages like Java/C#/PHP/JSP/ASP/etc runs on the server side. Yet you didn't mention which one you're using. The answer depends on that. So please mention and tag which one you're using. Based on your question history it's PHP. Is this true? If so, then this question is a dupe of stackoverflow.com/questions/198346/… Commented Apr 11, 2011 at 21:59
  • 5
    What is your backend language? You cannot just put HTML on a page and expect your web browser to upload things to your computer. That would be a huge security flaw. Commented Apr 11, 2011 at 21:59

4 Answers 4

79
<form id="uploadbanner" enctype="multipart/form-data" method="post" action="#"> <input id="fileupload" name="myfile" type="file" /> <input type="submit" value="submit" id="submit" /> </form> 

To upload a file, it is essential to set enctype="multipart/form-data" on your form

You need that form type and then some php to process the file :)

You should probably check out Uploadify if you want something very customisable out of the box.

Sign up to request clarification or add additional context in comments.

2 Comments

type isn't even a valid attribute for a FORM element ..
It should be enctype="multipart/form-data" otherwise you will load only the file name and not the data.
24

You need enctype="multipart/form-data" otherwise you will load only the file name and not the data.

2 Comments

There is no need to echo other comments. The answer was already edited to contain this.
No, because "otherwise you will load only the file name" is a really helpful information, so this answer is significant.
2

you will need to have a backend on the server do handle the file upload request you can base your backend with this php example

<?php $file = $_FILES['file']; move_uploaded_file($file['tmp_name'], 'uploads/' . $file['name']);?> 

Then point the form to the file

<form id="uploadbanner" enctype="multipart/form-data" method="post" action="/tourscript.php"> <input id="fileupload" name="myfile" type="file" /> <input type="submit" value="submit" id="submit" /> </form> 

Comments

1

On top of what the others have already stated, some sort of server-side scripting is necessary in order for the server to read and save the file.

Using PHP might be a good choice, but you're free to use any server-side scripting language. http://www.w3schools.com/php/php_file_upload.asp may be of use on that end.

2 Comments

It isn't fine. As Calum pointed out 4 years ago, it is missing the enctype attribute.
well, I thought it would be redundant if I say the same thing again that's all ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.