Implementation Method: form submit, submit after php program Processing
The form is as follows:
<Form action = "" enctype = "multipart/form-data" method = "post" name = "upform"> <div id = "addFile"> <a href = "# ">>> Add document </a> <span> Add document: <select id = "filetype" name = "filetype"> <option value = "select"> file type </option> <option value = "word"> word </option> <option value = "ppt"> ppt </option> <option value = "pdf"> pdf </option> <option value = "video"> mp4 </option> </select> <input name = "upfile" type = "file"/> <input type = "submit" name = "submit" value = "Confirm upload"/> <span> </div> </form>
The php code is as follows:
<? If ($ _ POST ['submit '] & is_uploaded_file ($ _ FILES ['upfile'] ['tmp _ name']) {$ upfile = $ _ FILES ["upfile"]; $ name = $ upfile ["name"]; $ size = $ upfile ["size"]; $ tmp_name = $ upfile ["tmp_name"]; $ error = $ upfile ["error"]; $ filetype = $ _ POST ['filetype']; $ localhost = "http: //*. *. *. * "; switch ($ _ POST ['filetype']) {case 'ppt ': $ OK = 1; $ dir =" coursefile/ppt/"; break; case 'word': $ OK = 1; $ dir = "coursefile/word /"; Break; case 'pdf ': $ OK = 1; $ dir = "coursefile/pdf/"; break; case 'video': $ OK = 1; $ dir = "coursefile/video/"; break; default: $ OK = 1; $ dir = "coursefile/video/"; break ;} if (file_exists (iconv ("UTF-8", "gb2312", $ dir. $ name) {$ status = 8; $ mes = "Upload Failed. A file with the same name already exists! "; Echo $ mes;} else {move_uploaded_file ($ tmp_name, iconv (" UTF-8 "," gb2312 ",".. /.. /". $ dir. $ name); $ SQL = "insert into courseFile (fileID, fileName, fileType, filePath, courseID) values ('', '$ name',' $ filetype ', '$ dir $ name',' $ courseid') "; mysql_query ($ SQL); $ url =" course_detail.php? CourseID = $ courseID "; echo" <script> window. location. href = '$ url'; </script> ";}}?>