我编写了这个脚本,让用户上传个人资料图片:
if(isset($_POST['submit'])){
$path = $_FILES["uploaded_image"]["name"];
$ext = pathinfo($path, PATHINFO_EXTENSION); //extracts file extension
$tempimgloc = $_FILES["uploaded_image"]["tmp_name"];
$imagepic = ''.$_SESSION['userid'].'-'.$_SESSION['username'].'.'.$ext.'';
$img_url = 'img/uploaded/'.$imagepic.'';
if(move_uploaded_file($tempimgloc, "img/uploaded/".$imagepic)){
mysql_query('UPDATE table SET img = "'.$img_url.'" WHERE userid = '.$_SESSION['userid'].'');
echo '<script>window.location = "success.php";</script>';
} else {
echo 'error';
}
}
现在我想要的是让他们只上传扩展名为png
或jpg
的文件。
我试图将它添加到上面的if语句中,但它没有用完:
if($ext == 'jpg' or $ext == 'png'){
...
}
感谢您的帮助!