A, HTML code is as follows:
<form name="form2" method="post" action="?type=add" enctype="multipart/form-data"> <input type="file" name="file" id="cover" required/> </form>
Two, PHP code is as follows:
IF (( $ _GET [ "of the type"] == "the Add") && $ _POST ) { // determine whether the uploaded file error, that is the case, an error is returned IF ( $ _FILES [ "File"] [ "error" ]) { echo $ _FILES [ "file"] [ "error" ]; Exit ; } the else { // no error // condition limitation // file type is determined to upload or png and jpg size not exceeding 1024000B IF (( $ _FILES [ "File"] [ "of the type"] == "Image / PNG" || $ _FILES [ "File"] [ "of the type"] == "Image / jpeg") &&$_FILES["file"]["size"]<1024000) { //Prevent duplicate file names $ path = "/ Upload / Movie /." DATE ( 'Ym of-D') "/.". Time (). $ _FILES [ "File"] [ "name" ]; $ filename = $ _SERVER [ 'DOCUMENT_ROOT']. $ path ; // check the file or directory exists iF ( the file_exists ( $ filename )) { echo "that the file already exists" ; Exit ; } the else { // save the file, move file uploaded move_uploaded_file to a new position IF (! @ Copy ( $ _FILES[ 'File'] [ 'tmp_name'], $ file_name )) { IF ( move_uploaded_file ( $ _FILES [ 'File'] [ 'tmp_name'], $ filename )) { echo "Upload successful" ; } the else { echo "Upload failed " ; Exit ; } } } } the else { echo " file type is wrong " ; } } }