Create a file upload form
It is very useful to allow users to upload files from forms.
Create a file upload form
It is very useful to allow users to upload files from forms.
See the following html form for uploading files:
Copy the code as follows:
<Html>
<Body>
<Form action = "upload_file.php tutorial" 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>
</Html>
Pay attention to the following information about this form:
<Form> The enctype attribute of a tag specifies the content type to be used when submitting a form. When a form requires binary data, such as file content, use multipart/form-data ".
<Input> the type = "file" attribute of the tag specifies that the input should be processed as a file. For example, when previewing in a browser, a browser button is displayed next to the input box.
Note: allowing users to upload files is a huge security risk. Only trusted users are allowed to upload files.
Create Upload script
The "upload_file.php" file contains the code for uploading files:
Copy the code as follows:
<? Php
If ($ _ files ["file"] ["error"]> 0)
{
Echo "error:". $ _ 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 "stored in:". $ _ files ["file"] ["tmp_name"];
}
?>