PHP: Get file extension not working on uploads to S3

后端 未结 12 641
我寻月下人不归
我寻月下人不归 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:34

    What happends if you:

    $filename = "${filename}";
    echo $filename;
    die();
    

    Do you get something like 'Dog.png'? If you don't there is something wrong in the way you are getting the filename. If you do get something like 'Dog.png', here is what I use to get the file extension.

    $pieces = explode('.',trim($filename));
    $extension = end($pieces);
    

    Then you should be able to do this:

    $params->key = rand_string(5).'.'.$extension;
    

提交回复
热议问题