Html file
[Html]
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml" lang = "zh-CN">
<Head>
<Title> HTML5 drag-and-drop upload </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Meta name = "description" content = ""/>
<Meta name = "keywords" content = ""/>
<Style type = "text/css">
# Dropzone {
Width: 300px;
Height: 300px;
Border: 2px dashed gray;
}
# Dropzone. over {
Border: 2px dashed orange;
}
</Style>
</Head>
<Body>
<H1> drag/drop upload <Div id = "dropzone"> </div>
</Body>
<Script type = "text/javascript">
// Sends data through ajax.
Function up (fd ){
Var xhr = new XMLHttpRequest ();
Xhr. open ('post', 'upfile. php', true); // asynchronous transmission
// Xhr. upload this is a new html5 api that stores information during the upload process.
Xhr. upload. onprogress = function (ev ){
Var percent = 0;
If (ev. lengthComputable ){
Percent = 100 * ev. loaded/ev. total;
// Document. getElementById ('progress'). innerHTML = percent;
Document. getElementById ('bar'). style. width = percent + '% ';
}
}
Xhr. send (fd );
}
Var dz = document. getElementById ('dropzone ');
Dz. ondragover = function (ev ){
This. className = 'over ';
Return false;
}
Dz. ondragleave = function (){
This. className = '';
}
Dz. ondrop = function (ev ){
// Console. log (ev. dataTransfer. files [0]);
Var fd = new FormData ();
Fd. append ('pic ', ev. dataTransfer. files [0]);
Up (fd );
Return false; // intercept normal drag and drop Behaviors
}
</Script>
</Html>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml" lang = "zh-CN">
<Head>
<Title> HTML5 drag-and-drop upload </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Meta name = "description" content = ""/>
<Meta name = "keywords" content = ""/>
<Style type = "text/css">
# Dropzone {
Width: 300px;
Height: 300px;
Border: 2px dashed gray;
}
# Dropzone. over {
Border: 2px dashed orange;
}
</Style>
</Head>
<Body>
<H1> drag/drop upload <Div id = "dropzone"> </div>
</Body>
<Script type = "text/javascript">
// Sends data through ajax.
Function up (fd ){
Var xhr = new XMLHttpRequest ();
Xhr. open ('post', 'upfile. php', true); // asynchronous transmission
// Xhr. upload this is a new html5 api that stores information during the upload process.
Xhr. upload. onprogress = function (ev ){
Var percent = 0;
If (ev. lengthComputable ){
Percent = 100 * ev. loaded/ev. total;
// Document. getElementById ('progress'). innerHTML = percent;
Document. getElementById ('bar'). style. width = percent + '% ';
}
}
Xhr. send (fd );
}
Var dz = document. getElementById ('dropzone ');
Dz. ondragover = function (ev ){
This. className = 'over ';
Return false;
}
Dz. ondragleave = function (){
This. className = '';
}
Dz. ondrop = function (ev ){
// Console. log (ev. dataTransfer. files [0]);
Var fd = new FormData ();
Fd. append ('pic ', ev. dataTransfer. files [0]);
Up (fd );
Return false; // intercept normal drag and drop Behaviors
}
</Script>
</Html>
Upfile. php
[Php]
Echo move_uploaded_file ($ _ FILES ['pic '] ['tmp _ name'],'. /upload /'. $ _ FILES ['pic '] ['name'])? 'OK': 'fail ';
Echo move_uploaded_file ($ _ FILES ['pic '] ['tmp _ name'],'. /upload /'. $ _ FILES ['pic '] ['name'])? 'OK': 'fail ';