Jump to content

Shouldnt this be echoing something else?!


Allenph9

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.