开发者

how to upload a file to my server using html

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

<form id = "uploadbanner" method = "post" ac开发者_高级运维tion = "#">
      <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.


<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.


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


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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜