PHP+MySQL+Smarty站点注册页MP4上传失败问题求助
Hey there! Let’s tackle that frustrating MP4 upload issue you’re facing—seeing progress hit 99% then getting a "file format is unknown" error with a backend white screen is no fun, especially since JPGs work fine. Let’s break down the most likely causes and fixes step by step:
1. MIME Type Validation is Missing MP4 Support
Chances are your backend code is only checking for image MIME types and hasn’t included video/mp4. The $_FILES['file']['type'] value can sometimes be unreliable (browser-dependent), so using PHP’s finfo extension to detect the actual file type is more robust.
Fix Example:
// Enable error reporting temporarily to debug the white screen error_reporting(E_ALL); ini_set('display_errors', 1); // Validate file type with finfo $finfo = new Finfo(FILEINFO_MIME_TYPE); $actual_mime = $finfo->file($_FILES['your_upload_field']['tmp_name']); $allowed_mimes = [ 'image/jpeg', 'image/png', 'video/mp4' // Add this line to allow MP4s! ]; if (!in_array($actual_mime, $allowed_mimes)) { die("file format is unknown"); }
2. Upload File Size Limits Are Too Low
MP4 files are almost always larger than JPGs, so your PHP or server config might be cutting off the upload before it completes. Check these settings in your php.ini file:
upload_max_filesize: Set to a value larger than your typical MP4 (e.g.,20M)post_max_size: Must be larger thanupload_max_filesize(e.g.,25M)max_execution_time: Increase to give enough time for the upload (e.g.,60seconds)memory_limit: Ensure it’s sufficient for handling file uploads (e.g.,128M)
Don’t forget to restart your web server (Apache/Nginx) after updating these settings.
3. File Extension Filtering Blocks MP4
If your code checks file extensions instead of (or in addition to) MIME types, make sure .mp4 is included in the allowed list. Also, account for uppercase extensions like .MP4:
Fix Example:
$filename = $_FILES['your_upload_field']['name']; $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $allowed_extensions = ['jpg', 'jpeg', 'png', 'mp4']; // Add mp4 here if (!in_array($extension, $allowed_extensions)) { die("file format is unknown"); }
4. Backend White Screen: Enable Error Reporting
The white screen means PHP is throwing an error but isn’t displaying it. Adding the error reporting lines at the top of your upload handler script (like in the first example) will show you exactly what’s going wrong—whether it’s a permission issue, memory limit hit, or uncaught exception.
5. Check Server-Level Upload Limits
If you’re using Nginx, verify client_max_body_size in your server config is set high enough. For Apache, check if mod_security is blocking large file uploads or specific MIME types.
Quick Checklist Before Testing Again
- Double-check the upload directory has write permissions for the PHP process (e.g.,
chmod 755 /path/to/upload/folder) - Ensure your frontend form’s
acceptattribute includesvideo/mp4(optional but helps guide users:<input type="file" accept="image/*, video/mp4">)
Once you’ve addressed these areas, test the MP4 upload again—this should resolve the 99% progress error and the white screen.
内容的提问来源于stack exchange,提问作者user27240

