New HTML page a.html
Note: Allowing users to upload files is a huge security risk. Please allow only trusted users to perform file upload operations. <form action= "b.php" method= "POST" enctype= "Multipart/form-data" > <label for= "file" >filename: </label><input type= "File" name= "file" id= "file"/> <br/><input type= "Submit" name= "Submit" value = "Submit"/></form></body>New b.php
By using PHP's global array $_files, you can upload files from a client computer to a remote server.
The first parameter is the input name of the form, and the second subscript can be "name", "type", "Size", "Tmp_name" or "error". Just like this:
$_files["File" ["Name"]-the name of the file being uploaded
$_files["File" ["type"]-the type of file being uploaded
$_files["File" ["Size"]-the size of the uploaded file, measured in bytes
$_files["File" ["Tmp_name"]-the name of the temporary copy of the file stored on the server
$_files["File" ["Error"]-error code caused by file upload
<?php
Determine the file upload type is not more than 20kif ((($_files["file"] ["type"] = = "Image/gif") | | ($_files["File" ["type"] = = "Image/jpeg") | | ($_files["File" ["type"] = = "Image/pjpeg")) && ($_files["File" ["Size"] < 20000) {if ($_files["file"] ["error"] > 0) {echo "Return Code:". $_files["File" ["Error"]. "<br/>"; } else {echo "Upload:". $_files["File" ["Name"]. "<br/>"; echo "Type:". $_files["File" ["type"]. "<br/>"; echo "Size:". ($_files["File" ["Size"]/1024). "Kb<br/>"; echo "Temp file:". $_files["File" ["Tmp_name"]. "<br/>"; Determine if the current directory upload (need to be created manually) exists for this file if (file_exists ("upload/". $_files["File" ["Name"])) {echo $_files["file"] [" Name "]. "already exists."; } else {
Does not exist save it in this folder Move_uploaded_file ($_files["file"] ["Tmp_name"], "upload/". $_files["File" ["name"]); echo "Stored in:". " Upload/". $_files["File" ["Name"]; }}}else {echo "Invalid file"; }?>
File Upload php