且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

限制PHP表单上传的文件类型和大小

更新时间:2023-11-19 18:01:28

您可以在php.ini中限制上传大小( here ),你可以检查上传文件名称的扩展名,以确认它是一个可接受的格式(未经测试的代码):

You can limit the upload size in php.ini (here), and you can check the extension of the name of the uploaded file to verify it is an acceptable format (not tested code):

$okExtensions = array('jpg', 'png');
$fileName = 'test.doc';

$fileParts = explode('.', $fileName);

if( in_array( strtolower( end($fileParts) ), $okExtensions) )
{
  // proceed
}