Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Uploading problem

AgentSaenzAgentSaenz Posts: 8Member
I have this code block to restrict files uploaded to just images.

if (($_FILES['upload']['type'] != 'image/gif')
|| ($_FILES['upload']['type'] != 'image/jpeg')
|| ($_FILES['upload']['type'] != 'image/jpg')
|| ($_FILES['upload']['type'] != 'image/bmp')
|| ($_FILES['upload']['type'] != 'image/png') )
{
echo($_FILES['upload']['type']);
die("Not right file formatt. gif, jpeg, jpg,bmp, and png only");
}

But when I test it, I get the die message, even though I know my file type is correct. I even echo out the $_FILES['upload']['type']

and I get image/jpeg

Any ideas on what is wrong with my code?

Comments

  • tradmtradm Posts: 49Member
    : I have this code block to restrict files uploaded to just images.
    :
    : if (($_FILES['upload']['type'] != 'image/gif')
    : || ($_FILES['upload']['type'] != 'image/jpeg')
    : || ($_FILES['upload']['type'] != 'image/jpg')
    : || ($_FILES['upload']['type'] != 'image/bmp')
    : || ($_FILES['upload']['type'] != 'image/png') )
    : {
    : echo($_FILES['upload']['type']);
    : die("Not right file formatt. gif, jpeg, jpg,bmp, and png only");
    : }
    :
    : But when I test it, I get the die message, even though I know my
    : file type is correct. I even echo out the $_FILES['upload']['type']
    :
    : and I get image/jpeg
    :
    : Any ideas on what is wrong with my code?
    :
    :


    Ur code has a LOGICAL error. U should not use an or ||, use && (and) operator to join the expressions

    ie

    [code]if (($_FILES['upload']['type'] != 'image/gif')
    && ($_FILES['upload']['type'] != 'image/jpeg')
    && ($_FILES['upload']['type'] != 'image/jpg')
    && ($_FILES['upload']['type'] != 'image/bmp')
    && ($_FILES['upload']['type'] != 'image/png')[/code]


    Think over it, u will understand why :)
  • AgentSaenzAgentSaenz Posts: 8Member
    : : I have this code block to restrict files uploaded to just images.
    : :
    : : if (($_FILES['upload']['type'] != 'image/gif')
    : : || ($_FILES['upload']['type'] != 'image/jpeg')
    : : || ($_FILES['upload']['type'] != 'image/jpg')
    : : || ($_FILES['upload']['type'] != 'image/bmp')
    : : || ($_FILES['upload']['type'] != 'image/png') )
    : : {
    : : echo($_FILES['upload']['type']);
    : : die("Not right file formatt. gif, jpeg, jpg,bmp, and png only");
    : : }
    : :
    : : But when I test it, I get the die message, even though I know my
    : : file type is correct. I even echo out the $_FILES['upload']['type']
    : :
    : : and I get image/jpeg
    : :
    : : Any ideas on what is wrong with my code?
    : :
    : :
    :
    :
    : Ur code has a LOGICAL error. U should not use an or ||, use && (and)
    : operator to join the expressions
    :
    : ie
    :
    : [code]: if (($_FILES['upload']['type'] != 'image/gif')
    : && ($_FILES['upload']['type'] != 'image/jpeg')
    : && ($_FILES['upload']['type'] != 'image/jpg')
    : && ($_FILES['upload']['type'] != 'image/bmp')
    : && ($_FILES['upload']['type'] != 'image/png')[/code]:
    :
    :
    : Think over it, u will understand why :)
    :
    I think I understand. That's what I get for simply cutting and pasting code directly from the Internet. Sometimes I feel as if I odnt really program, I just assemble (no pun on the assembly language intended) code together from the Internet and past projects using cut (cntr c) and paste (cntr v)
Sign In or Register to comment.