Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Why Do You Need to Filter Out Empty Files
Why Do You Need to Filter Out Empty Files? - PHP Script Tips - Uploading Files to Web Servers
✍: 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");
?>
2007-04-19, 4912👍, 0💬
Popular Posts:
How To Use Subqueries in the FROM clause? - MySQL FAQs - SQL SELECT Statements with JOIN and Subquer...
Where are all .NET Collection classes located ? System.Collection namespace has all the collection c...
What is synchronization and why is it important? With respect to multithreading, synchronization is ...
How Large Can a Single Cookie Be? - PHP Script Tips - Understanding and Managing Cookies How large c...
What Is Paint Shop Pro? - PSP Tutorials - Fading Images to Background Colors with PSP Paint Shop Pro...