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

How to upload files in php

coldplay.xixi
coldplay.xixiOriginal
2020-08-20 10:27:372475browse

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);

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!

Statement:
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