[英]upload only jpg and png format images in database through php
If an uploaded image is other than jpg
and png
format file, insertion of values into database will not work and form will not get submitted.如果上传的图像不是jpg
和png
格式的文件,则无法将值插入数据库,并且不会提交表单。
$extensions= array("jpeg","jpg");
if(in_array($file_ext,$extensions)=== false) {
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if(empty($errors)==true) {
move_uploaded_file($file_tmp,$file_name);
echo "Success";
}
else {
print_r($errors);
}
Try this:尝试这个:
$extensions= array("jpeg","jpg");
$errors='';
if(!in_array($file_ext,$extensions)){
$errors="extension not allowed, please choose a JPEG or PNG file.";}
if($errors=='') {
move_uploaded_file($file_tmp,$file_name);
echo "Success";
}else{
print_r($errors);
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.