I have the following code to upload an image using a form. I have added a button to the form to use to remove the image, but I cannot figure out how to code the button to remove the users image. (memberFiles/$id.".jpg")
Here is my code to upload an image. I'd like to add code to remove an image. Any ideas?
<?php
session_start();
$id = $_SESSION['recid'];
$school = $_SESSION['college'];
// Process the form if it is submitted
if ($_FILES['uploadedfile']['tmp_name'] != "") {
// Run error handling on the file
// Set Max file size limit to 120kb
$maxfilesize = 120000;
// Check file size, if too large exit
if($_FILES['uploadedfile']['size'] > $maxfilesize ) {
echo "Image too large.";
unlink($_FILES['uploadedfile']['tmp_name']);
exit();
// Check file extension to see if it is .jpg or .gif, if not exit
} else if (!preg_match("/\.(gif|jpg)$/i", $_FILES['uploadedfile']['name'] ) ) {
echo "Image not .gif or .jpg.";
unlink($_FILES['uploadedfile']['tmp_name']);
exit();
// If no errors on the file process it and upload to server
} else {
// Rename the pic
//Use the users numerical id to name the image file
$newname = $id.".jpg";
// Set the upload folder
// Upload the file
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "memberFiles/".$newname)) {
echo "Image uploaded.";
exit();
} else {
echo "Upload error";
exit();
}
}
}
?>