Reputation: 15459
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.
Upvotes: 52
Views: 188023
Reputation: 21
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>
Upvotes: 2
Reputation: 5316
<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.
Upvotes: 77
Reputation: 9542
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.
Upvotes: 1
Reputation: 577
You need enctype="multipart/form-data"
otherwise you will load only the file name and not the data.
Upvotes: 23