目前我已经允许上传 .jpg 文件。
如何添加 jpeg、gif 和 png?
我当前的代码如下...
$filename = basename($_FILES['photo']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
//Check if the file is JPEG image and it's size is less than 5Mb
$allowedExts = array('jpg', 'jpeg', 'gif', 'png');
if ( (in_array($ext, $allowedExts)) && ($_FILES["photo"]["type"] == "image/jpeg") && ($_FILES["photo"]["size"] <= 5242880) ){
//Determine the path to which we want to save this file
$newname = str_replace( ' ', '_', trim( strip_tags( $_POST['name'] ) ) ) . _ . $formKey->generateKey() . '_' . time() . '.jpg';