When uploading files, you need to pay attention to the php.ini file.

You need to pay attention to the php.ini file when uploading files

Before formally explaining the upload in this chapter, the first thing we need to pay attention to is the php.ini file.

This is our first introduction to how to modify the php.ini file. If your configuration items are inconsistent with what we said, please pay attention to the modification.

Let’s understand each configuration item.

Let’s take a look at how to modify php.ini.

There are too many php.ini files. If you can’t find them, you can use ctrl+f to search for related configuration items.

##file_uploads on is to turn on the file upload function, off is to turn it off post_max_size The maximum value of POST parameters allowed by the system upload_max_filesize The maximum size of uploaded files allowed by the system memory_limit Memory usage limit
Configuration item Function description

Recommended size: file_size (file size) < upload_max_filesize < post_max_size < memory_limit

In addition, you need to pay attention to the script execution time.

max_execution_time, the unit of this parameter is seconds.

This parameter is to set the maximum execution time of the script.
You can also make appropriate changes according to your needs. Usually there is no need to modify it, the system default value is enough. When uploading very large files, this parameter may be modified.

The upload time is too long and will time out. If you set this parameter to 0, the timeout period is not limited and is not recommended.

After completing the relevant configuration of php.ini, we can start trying to complete the first file upload.


Continuing Learning
||
上传文件:
* 1:超过了文件大小,在php.ini文件中设置
* 2:超过了文件的大小MAX_FILE_SIZE选项指定的值
* 3:文件只有部分被上传
* 4:没有文件被上传
* 5:上传文件大小为0 */ $error=$upfile["error"];//上传后系统返回的值 echo "================
"; echo "上传文件名称是:".$name."
"; echo "上传文件类型是:".$type."
"; echo "上传文件大小是:".$size."
"; echo "上传后系统返回的值是:".$error."
"; echo "上传文件的临时存放路径是:".$tmp_name."
"; echo "开始移动上传文件
"; //把上传的临时文件移动到up目录下面 move_uploaded_file($tmp_name,'up/'.$name); $destination="up/".$name; echo "================
"; echo "上传信息:
"; if($error==0){ echo "文件上传成功啦!"; echo "
图片预览:
"; echo ""; //echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\">"; }elseif ($error==1){ echo "超过了文件大小,在php.ini文件中设置"; }elseif ($error==2){ echo "超过了文件的大小MAX_FILE_SIZE选项指定的值"; }elseif ($error==3){ echo "文件只有部分被上传"; }elseif ($error==4){ echo "没有文件被上传"; }else{ echo "上传文件大小为0"; } }else{ echo "请上传jpg,gif,png等格式的图片!"; } } ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!