[英]How to add image extension dynamically?
我的問題是如何動態添加圖像擴展名。因此,當用戶更新其配置文件時,它可以顯示所有圖像類型,例如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}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.