Skip to content
PHP Logo

How can PHP developers effectively communicate to users that file uploads may take some time?

To effectively communicate to users that file uploads may take some time, PHP developers can display a loading spinner or progress bar on the webpage during the upload process. This visual indicator can help manage user expectations and reduce frustration while waiting for the upload to complete.

php
<!-- Display a loading spinner during file upload -->
<!DOCTYPE html>
<html>
<head>
    <title>File Upload</title>
    <style>
        .spinner {
            display: none;
            width: 50px;
            height: 50px;
            border: 5px solid #f3f3f3;
            border-top: 5px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 0 auto;
            margin-top: 20px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <h1>File Upload</h1>
    <form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="file" name="file">
        <button type="submit">Upload</button>
    </form>
    <div class="spinner"></div>

    <script>
        document.querySelector('form').addEventListener('submit', function () {
            document.querySelector('.spinner').style.display = 'block';
        });
    </script>
</body>
</html>