Home >Backend Development >PHP Problem >How to upload files in php
How to upload files in php: first get the content of the uploaded file from the form; then paste the code for uploading the file; finally, convert the format encoding of the file name into [utf-8].
php method to upload files:
1, first get the uploaded file content from the form:
Note: When uploading files, the attributes of the form must be added enctype="multipart/form-data"
##$filedata = $_FILES ['file'];
$filename = $filedata['name']; move_uploaded_file($filedata['tmp_name'],'/uploads/file/'.$filename);3. When executing the above code, you will find a problem, that is, if the file name we upload is Chinese , when moving to a certain directory, the file name will become garbled. At this time, we need to convert the format encoding of the file name to utf-8. The code is as follows:
$filename = iconv('utf-8','gb2312',$filename);
Relevant learning recommendations:php programming (video)
The above is the detailed content of How to upload files in php. For more information, please follow other related articles on the PHP Chinese website!