Amazon_S3_And_CloudFront::wp_handle_upload_prefilter PHP Method

wp_handle_upload_prefilter() public method

Create unique names for file to be uploaded to AWS This only applies when the remove local file option is enabled
public wp_handle_upload_prefilter ( array $file ) : array
$file array An array of data for a single file.
return array $file The altered file array with AWS unique filename.
    function wp_handle_upload_prefilter($file)
    {
        if (!$this->get_setting('copy-to-s3') || !$this->is_plugin_setup()) {
            return $file;
        }
        $filename = $file['name'];
        // sanitize the file name before we begin processing
        $filename = sanitize_file_name($filename);
        // separate the filename into a name and extension
        $info = pathinfo($filename);
        $ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
        $name = basename($filename, $ext);
        // edge case: if file is named '.ext', treat as an empty name
        if ($name === $ext) {
            $name = '';
        }
        // rebuild filename with lowercase extension as S3 will have converted extension on upload
        $ext = strtolower($ext);
        $filename = $info['filename'] . $ext;
        $time = current_time('mysql');
        // Get time if uploaded in post screen
        $post_id = filter_input(INPUT_POST, 'post_id', FILTER_VALIDATE_INT);
        if (isset($post_id)) {
            $time = $this->get_post_time($post_id);
        }
        if (!$this->does_file_exist($filename, $time)) {
            // File doesn't exist locally or on S3, return it
            return $file;
        }
        $file['name'] = $this->generate_unique_filename($name, $ext, $time);
        return $file;
    }
Amazon_S3_And_CloudFront