Page 165 - Open Soource Technologies 304.indd
P. 165
Open Source Technologies
Notes set in the upload_max_filesize field in your php.ini file that defaults to 2MB. The MAX_FILE_SIZE
field is obeyed at the browser’s discretion, so you should rely on the php.ini setting to cap
unreasonable uploads. After the MAX_FILE_SIZE field has been entered, you’re ready to add
the upload field itself. This is simply an INPUT element with a TYPE argument of “file”. You
can give it any name you want. Listing 13 brings all this together into an HTML upload form.
Listing 13 A Simple File Upload Form
<?php
$uploaddir = ‘/var/www/uploads/’;
$uploadfile = $uploaddir . basename($_FILES[‘userfile’][‘name’]);
echo “<p>”;
if (move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], $uploadfile))
{
echo “File is valid, and was successfully uploaded.\n”;
}
else
{
echo “Upload failed”;
}
echo “</p>”;
echo ‘<pre>’;
echo ‘Here is some more debugging info:’;
print_r($_FILES);
print “</pre>”;
?>
1. Create email to send script.
2. Create the File Upload Form
9.10 Summary
• The more standard HTML you can leave in your pages, the easier they are for designers
and page builders to amend without reference to you.
• A hidden field behaves exactly the same as a text field, except that the user cannot see it
unless he views the HTML source of the document that contains it.
• After making any changes to php.ini on any platform, you must restart the web server
process for the changes to take effect.
160 LOVELY PROFESSIONAL UNIVERSITY