In: Computer Science
PHP Question -
Subject: PHP File Handling and Uploads
INSTRUCTIONS:
Objective:
• Create a sticky HTML form.
• Submit form for processing.
• Sanitize and validate form data.
• Upload a profile image.
• Add a record to a text file.
• Display form results with content from another text file and the
uploaded image.
Description:
This assignment deals with file management. It requires the use of 3 new files and 1 new directory. You will create the new file-uploads.php file, a new membership.txt file to record form data, a poem.txt file to store a "poem" of your choice and a new images directory. All information in this assignment is processed and displayed using the file-uploads.php page. There are no redirects.
You will need to build a form to upload user images and access a couple of files on the server. The form will be processed and validated. The sanitized and validated form information will be saved to a text file (membership.txt) you create on the server. Once the form has been processed and the image uploaded to the new images directory, you will not redirect the user to a new page to display the results as specified. Instead, you will code the existing page to process the form, including the image upload, then display the formatted information (instead of the form) along with some information from a text file (poem.txt) you create.
Requirements:
Create a PHP page named file-uploads.php with a form using the following field controls:
• Single line text box for the user's first name.
• Single line text box for the user's last name.
• Single line text field for email.
• Single line text field for password.
• Single line text field for password verify.
• Add a file control to the form to upload a profile image
file.
Process the form text information.
• Upon form submission, sanitize and validate the text
information.
• If the information is valid, create a new lowercase username with
the first initial of the first name concatenated with the last
name. (IE: sherd)
• Set the first letter of the first and last names to uppercase
then concatenate the first name and last name into one field with a
separation space between the names.
• Append the membership.txt file with the user's name, email,
password and new username.
Process the image upload.
• Add validation to make sure the image file is an appropriate
image type and size is 100KB or less.
• If the image passes validation, check to see if it already
exists. If so, display an error and return the form to the
user..
• If the image file doesn't exist, upload the image to the
server.
Style and prep the HTML in both pages.
• Include the functions file.
• Wrap the page output in your header and footer.
• Utilize the Bootstrap framework to style your page contents.
Add form processing to the file to sanitize and validate the form submission. Include sticky form fields and error messages.
• Text fields must be present and convert any HTML tags present
using htmlspecialchars().
• Text fields and passwords must be trimmed using trim().
• Email must validate using preg_match().
• Convert all names in name field to first letter uppercase.
• All form fields must be checked for content. Any missing content
should trigger the form to be redisplayed to the user with a
warning to provide acceptable information.
file-uploads.php-
<!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form method='POST'> <h2>Please input your first name:</h2> <input type="text" name="Firstname">
<h2> Please input your last name</h2>
<input type ="text" name="Last name">
<h2>Please input your Email:</h2> <input type="text" name="Email">
<h2>Please input your Password:</h2> <input type="password" name="password">
<h2>Please input your confirm password:</h2> <input type="password" name="Confirm Password">
<h2>Please upload profile image:</h2> <input type="file" name="ProfileImage" id="ProfileImage">
</form> <?php //Retrieve name from query string and store to a local variable $name = $_POST['name']; echo "<h3> Hello $name </h3>"; ?> </body> </html>