PHP: Get file extension not working on uploads to S3

后端 未结 12 646
我寻月下人不归
我寻月下人不归 2020-12-06 17:49

I am using the Amazon S3 API to upload files and I am changing the name of the file each time I upload.

So for example:

Dog.png > 3Sf5f.png

Now I got

12条回答
  •  粉色の甜心
    2020-12-06 18:38

    You need to first find out what the original extension is and not rename the entire file. So keep the extension and rename de file name.

    Assuming you have image name in $image_name:

    $image_name = "image.png";
    $random_string = "random";
    
    list($filename,$fileext) = explode(".",$image_name);
    $new_name = $random_string.'.'.$fileext;
    rename($image_name,$new_name);  
    

提交回复
热议问题