Home > Backend Development > PHP Problem > How to upload files in php

How to upload files in php

coldplay.xixi
Release: 2023-03-04 20:24:01
Original
2474 people have browsed it

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].

How to upload files in php

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'];

2. Paste the code to upload the file:

$filename = $filedata['name'];
move_uploaded_file($filedata['tmp_name'],'/uploads/file/'.$filename);
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template