What are the best practices for creating and uploading animated GIF buttons in PHP forums?

When creating and uploading animated GIF buttons in PHP forums, it is important to optimize the file size of the GIF to ensure fast loading times and minimize bandwidth usage. Additionally, make sure to follow the forum's guidelines for file size limits and dimensions to prevent any issues with uploading. Finally, consider using a secure file upload method to prevent any security vulnerabilities.

// Example code for uploading animated GIF button in PHP forum

// Check if file is selected for upload
if(isset($_FILES['button'])) {
    $file_name = $_FILES['button']['name'];
    $file_size = $_FILES['button']['size'];
    $file_tmp = $_FILES['button']['tmp_name'];

    // Check file size and type
    $file_ext = strtolower(end(explode('.', $file_name)));
    $extensions = array("gif");
    
    if(in_array($file_ext, $extensions) === false){
        echo "Invalid file type, please upload a GIF file.";
    }

    // Check file size (max 2MB)
    if($file_size > 2097152){
        echo 'File size must be less than 2 MB';
    }

    // Move the uploaded file to desired directory
    move_uploaded_file($file_tmp, "uploads/".$file_name);
    echo "File uploaded successfully.";
}