简体   繁体   中英

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.

   <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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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