PHP: Get file extension not working on uploads to S3

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

    if you're uploading images try this

    $dim = getimagesize($file);
    $type = $dim[2];
    if( $type == IMAGETYPE_JPEG ) $ext=".jpg"; 
    if( $type == IMAGETYPE_GIF ) $ext=".gif"; 
    if( $type == IMAGETYPE_PNG ) $ext=".png";
    
    $params->key = rand_string(5).$ext;
    

提交回复
热议问题