Assignment Addendum: The Profile Image Module
Additional Marks: 3 Points
New Total: 13 Points
Overview
Now that we have covered file handling and server-side image processing, you are required to add a
Profile Picture feature to your Dynamic Resume.
This task requires you to modify your existing "Admin" section to allow uploading a professional
headshot, processing it, and displaying it on the public resume page.
Task Requirements
1. Database Update
• Alter your database to include a column (e.g., avatar_path) in your user/profile table to
store the file path of the uploaded image.
2. Admin Interface (The Upload)
• Modify your admin form to accept file uploads.
• HTML Requirement: You must correctly use the enctype="multipart/form-data"
attribute.
• The user should be able to select an image file from their computer and submit the form.
3. Server-Side Processing (The Logic)
• Storage: Create a directory named uploads/ on your server.
• Handling: Use the global $_FILES array to receive the file.
• Unique Naming: You must rename the uploaded file using a unique identifier (e.g.,
uniqid()) or a timestamp to prevent file overwriting (e.g., profile_65a1b2c3.jpg).
4. Validation & Security (Crucial)
• Type Check: Ensure the file is actually an image (Allow only .jpg, .jpeg, .png). Do not
trust the filename extension alone; check the MIME type.
• Size Check: Limit the file size to 2MB max. Return a friendly error message if the file is
too large.
• Error Handling: Check $_FILES['file']['error'] to ensure the upload was successful
before processing.
5. Image Manipulation (GD Library)
• When an image is uploaded, you must automatically create a smaller Thumbnail version
(e.g., 150x150 pixels) for the website to use.
• Use PHP's GD library functions (e.g., imagecreatefromjpeg, imagescale, imagejpeg) to
resize the image programmatically.
Marking Criteria (Addendum: 3 Points)
These points are distinct from the main 10-point rubric.
6. File Handling & Storage (1.0 Point)
• 0.5 pt: The HTML form is correctly configured, and the PHP script successfully moves the
file from the temporary directory to the uploads/ folder.
• 0.5 pt: The file path is correctly saved to the MySQL database, and the image displays
correctly on the public [Link] page.
7. Security & Robust Validation (1.0 Point)
• 0.5 pt: Validation: The script correctly rejects non-image files (like .pdf or .exe) and
rejects files larger than 2MB.
• 0.5 pt: Sanitization: The script renames the file upon upload to prevent directory
traversal attacks or overwriting existing files.
8. Image Processing (GD/Imagick) (1.0 Point)
• 1.0 pt: The system successfully generates a resized thumbnail of the uploaded image.
o Note: If you simply upload the full-size image and use CSS to resize it visually, you
will receive 0 points for this section. The file on the server must be physically resized
by PHP.
Hints for this Section
1. Permissions: If your upload fails, check that your uploads/ folder has write permissions
(on Linux/Mac, this is chmod 777 or 755).
2. GD Library: Ensure GD is enabled in your [Link] (uncomment ;extension=gd).
3. Flow: 1. Validate File -> 2. Move File -> 3. Resize/Create Thumbnail -> 4. Save Path to
DB.