php - 如何动态添加图片扩展?
问题描述
我的问题是如何动态添加图像扩展名。这样当用户更新其个人资料时,它可以显示所有图像类型,如 jpg png 或 jpeg。我知道我使用 png 但不知道如何动态添加扩展名。也请告诉我如何使照片独一无二,这样如果用户上传他的下一张个人资料图片,它可能不会被旧照片覆盖。
<img src="uploads/profile/profile'.$_SESSION['iduser'].'.png" class="img-
responsive "img-circle" alt="User Image" >
$files = $_FILES['uploadphoto'];
$fileName = $_FILES['uploadphoto']['name'];
$fileTmpName= $_FILES['uploadphoto']['tmp_name'];
$fileSize =$_FILES['uploadphoto']['size'];
$fileError =$_FILES['uploadphoto']['error'];
$fileType =$_FILES['uploadphoto']['type'];
$fileExt = explode('.',$fileName);
$fileActualExt =strtolower(end($fileExt));
if($fileType ='jpg' && $fileType ='png' && $fileType ='jpeg'){
if($fileError === 0){
if($fileSize < 5000000){
$fileNewName = "profile".$id.".".$fileActualExt;
$fileDestination ="uploads/profile/".$fileNewName;
move_uploaded_file($fileTmpName,$fileDestination);
$sqlImg = "UPDATE profilestatus SET status =0 WHERE iduser = '$id'";
mysqli_query($conn,$sqlImg);
}else{
echo "Your file is to big to upload!";
}
}else{
echo "There is an error!";
}
}
else{
echo "Photo cannot be uploaded! image is not of the type jpg png or
jpeg";
}
解决方案
您可以使用该功能
if([name of the added file] > NULL){you change the name}else{you save the file on the server}
推荐阅读
- twilio - 用于发送语音邮件 URL 的 Twilio Studio 功能
- r - 求一列数据的均值
- c - C使用void函数来计算文件的总和
- parsing - C# ANTLR4 DefaultErrorStrategy 或自定义错误侦听器不会捕获无法识别的字符
- kotlin - 如何在 tornadofx 中使用国际化
- xml - 如何总结 xslt 函数返回的值
- jquery - 仅当使用 jquery 单击第一列时如何激活功能?
- python - Django views.py 不呈现 html 文件?
- laravel - laravel 中未定义的变量(头疼)
- ios - iOS 13.4 应用程序崩溃,消息模糊:前提条件失败:类型检查失败:101,预期文本,得到 _HiddenModifier