Tools, FAQ, Tutorials:
Filtering Out Empty Files in PHP
Why Do You Need to Filter Out Empty Files in PHP?
✍: FYIcenter.com
When you are processing uploaded files, you need to check for empty files, because they could be resulted from a bad upload process but the PHP engine could still give no error. For example, if a user typed a bad file name in the upload field and submitted the form, the PHP engine will take it as an empty file without raising any error. The script below shows you an improved logic to process uploaded files:
<?php
$file = '\fyicenter\images\fyicenter.logo';
$error = $_FILES['fyicenter_logo']['error'];
$tmp_name = $_FILES['fyicenter_logo']['tmp_name'];
print("\n");
if ($error==UPLOAD_ERR_OK) {
if ($_FILES['fyicenter_logo']['size'] > 0) {
move_uploaded_file($tmp_name, $file);
print("File uploaded.\n");
} else {
print("Loaded file is empty.\n");
}
} else if ($error==UPLOAD_ERR_NO_FILE) {
print("No files specified.\n");
} else {
print("Upload faield.\n");
}
print("\n");
?>
⇒ Creating a Database Table to Store Files in PHP
⇐ Detecting File Uploading Errors in PHP
2016-10-14, ∼2982🔥, 0💬
Popular Posts:
Where to find tutorials on PHP language? I want to know how to learn PHP. Here is a large collection...
What is the Azure AD v1.0 OpenID Metadata Document? Azure AD v1.0 OpenID Metadata Document is an onl...
What is EPUB 3.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 3.0 Metadata "dc:publisher" ...
Where can I download the EPUB 2.0 sample book "The Metamorphosis" by Franz Kafka? You can following ...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...