如何动态添加图片扩展?

时间:2018-05-21 16:40:02

标签: 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";
       }

1 个答案:

答案 0 :(得分:0)

你可以使用这个功能

if([name of the added file] > NULL){you change the name}else{you save the file on the server}