The Solution of Uploading File in php
- 2021-11-01 23:52:04
- OfStack
1. Scenario description: In the development process, we always use uploading files. In fact, uploading files can be done by one method
2. Program
Code:
1. First get the uploaded file contents from the form form:
Note: When uploading files, the attribute of form form must be added with 1
enctype=“multipart/form-data”
$filedata = $_FILES['file'];
2. Paste the code for uploading files:
$filename = $filedata['name'];
move_uploaded_file($filedata['tmp_name'],'/uploads/file/'.$filename);
3. When executing the above code, we will find a problem, that is, if the file name we uploaded is Chinese, when moving to a certain directory, the file name will become garbled. At this time, we need to encode the format of the file name into utf-8. The code is as follows:
$filename = iconv('utf-8','gb2312',$filename);
Summarize