PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Uploading problem Posted by AgentSaenz on 26 Sept 2008 at 10:13 AM
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?

Report
Re: Uploading problem Posted by tradm on 28 Sept 2008 at 11:50 PM
: 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

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')



Think over it, u will understand why :)
Report
Re: Uploading problem Posted by AgentSaenz on 29 Sept 2008 at 7:25 AM
: : 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
:
:
: 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')
:
:
:
: 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)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.