简体   繁体   English

如何动态添加图像扩展名?

[英]How to add image extension dynamically?

MY problem is how to add the image extension dynamically.So that when the user updates its profile it can show all the image types like jpg png or jpeg.I know i have use png but dont know how to add dynamically extension.And also please tell me how can i make the photos unique so that if the user uploads his next profile image it may not get overwritten with the old one. 我的问题是如何动态添加图像扩展名。因此,当用户更新其配置文件时,它可以显示所有图像类型,例如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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM