Allenph9 Posted February 24, 2012 Share Posted February 24, 2012 I am probably making a dumb mistake...but heres the code... $gif = '.gif'; $jpg = '.jpg'; $jpeg = '.jpeg'; $png = '.png'; $jpeg1 = 'jpeg'; $gif1 = 'gif'; $jpg1 = 'jpg'; $png1 = 'png'; $max_file_size = '1048576'; $new_avatar = $_FILES['uploaded_avatar']['name']; $avatar_ext = end(explode('.', $new_avatar)); if (isset($_POST['change_submit1'])) { if ($_SESSION['logged_in'] != '1') { echo 'You need to be logged in!'; } elseif ($_POST['change_box1'] != 'CHANGE') { echo 'You must fill in the "CHANGE" box!'; } elseif (($uploaded_a_file == '1') && ($avatar_ext != $jpg1) && ($avatar_ext != $png1) && ($avatar_ext != $gif1) && ($avatar_ext != $jpeg1)) { echo 'File format not supported!'; } elseif ($uploaded_a_file != '1') { echo 'No file selected!'; } elseif ($_FILES["uploaded_avatar"]["size"] > $max_file_size) { echo 'File is too big!'; } } this is the code that should be echoing my avatar upload errors. Ive checked all the if statements ive changed the order around. still nothing. all of them work other than file format not supported. I can get this one to work...but at the cost of no file selected not working...help! Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 24, 2012 Share Posted February 24, 2012 so, what exactly is your issue? Are the errors not being displayed correctly when they should be? Quote Link to comment Share on other sites More sharing options...
Adam Posted February 24, 2012 Share Posted February 24, 2012 Debug the variables. Use var_dump to test each variable and make sure they're what you expect; namely $uploaded_a_file, $avatar_ext, $jpg1, $png1, $gif1 and $jpeg1. Given they're what you're testing with in the condition that doesn't work as expected. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 24, 2012 Share Posted February 24, 2012 Your problem is that you are getting the extension by explod()ing on the period. That means the period will not be part of the value, but all your validation values include periods. But the approach is overly-complicated and has another flaw. When comparing strings they will be compared on a case-sensitive manner. So, 'jpg' != 'JPG'. Plus, you don't need to make it so complicated. Simply make an array of acceptable extensions and do an in_array() check. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.