How to modify the image upload size in php: 1. Find the php configuration file php.ini, and then modify "post_max_size =12M"; 2. Add "ini_set('file_uploads'" in front of the file or image upload code ,'ON');" and other codes.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
Specific implementation method of setting the image file upload size in PHP
1.(1). Find the php configuration file php.ini(win), Linux may be: php.conf
(2). Modify: post_max_size =12M (the default value is: post_max_size =2M)
2. Add the following configuration settings in front of the file or image upload code:
//HTTP上传文件的开关,默认为ON即是开 ini_set('file_uploads','ON'); //通过POST、GET以及PUT方式接收数据时间进行限制为90秒 默认值:60 ini_set('max_input_time','90'); //脚本执行时间就由默认的30秒变为180秒 ini_set('max_execution_time', '180'); //Post变量由2M修改为8M,此值改为比upload_max_filesize要大 ini_set('post_max_size', '12M'); //上传文件修改也为8M,和上面这个有点关系,大小不等的关系。 ini_set('upload_max_filesize','10M'); //正在运行的脚本大量使用系统可用内存,上传图片给多点,最好比post_max_size大1.5倍 ini_set('memory_limit','20M');
Image upload case:
//上传图片 function uploadImg(){ ini_set("memory_limit","100M"); $base64Img = $GLOBALS['params']['base64Img']; $base64Img = str_replace(array("data:image/jpeg;base64,","data:image/png;base64,",'data:image/jpg;base64,',"'"), '', $base64Img); //ToolKit::_myLogln("data:",$base64Img, LOG_DIR.'base64_to_img_log'); $output_file = $GLOBALS['file_dir'].DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'lixin'.DIRECTORY_SEPARATOR.'h5_upload_tmp'.DIRECTORY_SEPARATOR.uniqid().'.png'; $url = base64_to_img($base64Img,$output_file); ToolKit::send(true, array('url'=>$url), '删除成功'); } function base64_to_img( $base64_string, $output_file ) { $ifp = fopen( $output_file, "wb" );//以二进制写入方式打开 fwrite( $ifp, base64_decode( $base64_string) ); fclose( $ifp ); return( $output_file ); }
Recommended Study: "PHP Video Tutorial"
The above is the detailed content of How to change image upload size in php. For more information, please follow other related articles on the PHP Chinese website!