DasHaas Posted August 3, 2007 Share Posted August 3, 2007 I have the following code that validates my form fields. I have a file field called file that I cant figure out how to validate. Any help will be greatly appreciated my code <?php // validate text input fields an check password if (trim($_POST['txtname']) == '') {$errorList[] = 'Please enter your name';} if (trim($_POST['txtemail']) == '') {$errorList[] = "Please enter your email address";} if (trim($_POST['txtphone']) == '') {$errorList[] = "Please enter your phone number";} if (trim($_POST['txtpassword']) == '') {$errorList[] = "Please enter a password";} if (trim($_POST['txtpassword1']) == '') {$errorList[] = "Please re-enter your password";} if (trim($_POST['sslimpressions']) == '') {$errorList[] = "Please select a number of impressions";} if (trim($_POST['ssladtype']) == '') {$errorList[] = "Please select ad type";} if (trim($_POST['txturl']) == '') {$errorList[] = "Please enter your website url";} if (trim($_POST['txtalt']) == '') {$errorList[] = "Please enter your business name";} if ($_POST['txtpassword'] != $_POST['txtpassword1']) {$errorList[] = "Passwords did not match";} if($_FILES['file']['size'] > 3000000) {$errorList[] = "Selected file is too large";} ?> i tried using: if($_FILES['file']['size'] = 0) {$errorList[] = "Please select a file";} but it did not work, it let me submit the form Link to comment https://forums.phpfreaks.com/topic/63131-file-field-validation-_files/ Share on other sites More sharing options...
btherl Posted August 3, 2007 Share Posted August 3, 2007 Try adding var_dump($_FILES) to the top of your script. That will show you the entire contents of the array. Then you can use that to determine what validation to add. Link to comment https://forums.phpfreaks.com/topic/63131-file-field-validation-_files/#findComment-314602 Share on other sites More sharing options...
kael.shipman Posted August 3, 2007 Share Posted August 3, 2007 To elaborate on the previous post, if the user doesn't submit a file, the files array will be empty, so all you have to do to see if the user submitted a file is if (isset($_FILES['file'])) { doSomething; }. Of course then you'd proceed to validating it by checking type and size and all, but it looks like you've got that going. Link to comment https://forums.phpfreaks.com/topic/63131-file-field-validation-_files/#findComment-314605 Share on other sites More sharing options...
DasHaas Posted August 3, 2007 Author Share Posted August 3, 2007 i tried: if (isset($_FILES['file'])) {$errorList[] = "Please select a file to upload";} but it gave me an error even when i selected a file Link to comment https://forums.phpfreaks.com/topic/63131-file-field-validation-_files/#findComment-314611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.