July 19, 200818 yr Hi all after much time trying to wok out how to upload a file from a contact form to a server i have done it now how do i restrict it so that it only allows jpg as i would imagine hackers could upload anything to the server ? here is my php <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> is there away i can make my script only allow jpg and jpeg extensions and i supose when i have sorted that out i will need to no how to send it in an email any tutorials any one thanks every one
July 19, 200818 yr Hi, for image uploads, I would set an array of allowed file types $oktypes = array('image/jpg', 'image/jpeg'); Then check the $_FILES array for the allowed types. if (in_array($_FILES['uploadedfile']['type'], $oktypes)) { carry on the form processing } Hope that helps.
Create an account or sign in to comment