[nycphp-talk] Using $_FILES["whatever"]["type"] correctly
Dan Cech
dcech at phpwerx.net
Wed Jan 14 10:11:53 EST 2004
Hi,
Webapprentice . wrote:
> Hi,
>
> I'm trying to compare the type of file I uploaded with certain MIME types as part of a series of checks.
There are definite issues with using the provided mime type as it is
provided by the browser. Realistically however you can probably get
away with it for most situations.
Once the script is running it may be an idea to put in some code to use
mime_content_type or file -ib to get a more accurate mime type.
> In one case, $imageType was equal to "image/jpeg" but it still fell into my error area.
> Why? I thought at first it was "short-circuiting" on the if statement, but that would apply to && conditions, right?
There is indeed an error in the construction of your if statement. Your
test will NEVER return FALSE.
A better routine would be:
if ($_FILES['frontimage']['name'] != '')
{
$imageType = $_FILES['frontimage']['type'];
// Check MIME Type
if (
!in_array(strtolower($imageType),array('image/png','image/jpeg','image/gif'))
)
{
$errorMessage['frontimage'] = 'Please upload images with the
extension .jpg or .jpeg or .gif or .png only.';
$errors = 1;
echo($imageType);
exit();
}
}
The critical line is:
!in_array(strtolower($imageType),array('image/png','image/jpeg','image/gif'))
Conceptually this makes a lot of sense, if the imagetype is not in the
array of 'good' types, throw an error.
The code will also be a lot faster because it eliminates several calls
to strtolower, and all the double-quotes are replaced with single-quotes.
Dan
> Thanks.
>
>
> Code snippet
> ------------
>
>
> if ($_FILES["frontimage"]["name"] != "")
> {
> $imageType = $_FILES["frontimage"]["type"];
>
> // Check MIME Type
> if ((strtolower($imageType) != "image/png") || (strtolower($imageType) != "image/jpeg") || (strtolower($imageType) != "image/gif"))
> {
> $errorMessage["frontimage"] = "Please upload images with the extension .jpg or .jpeg or .gif or .png only.";
> $errors = 1;
> echo($imageType);
> exit();
> }
> }
>
>From hans not junk at nyphp.com Wed Jan 14 10:35:19 2004
Return-Path: <hans not junk at nyphp.com>
Received: from ehost011-1.exch011.intermedia.net (unknown [64.78.21.3])
by virtu.nyphp.org (Postfix) with ESMTP id 9D49CA85A6
for <talk at lists.nyphp.org>; Wed, 14 Jan 2004 10:35:19 -0500 (EST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: RE: [nycphp-talk] Quoting and netiquette
Date: Wed, 14 Jan 2004 07:35:17 -0800
Message-ID: <41EE526EC2D3C74286415780D3BA9F87374BD8 at ehost011-1.exch011.intermedia.net>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: [nycphp-talk] Quoting and netiquette
Thread-Index: AcPZKN9547j6aHbvSxWW/1myRW6LnABiv20Q
From: "Hans Zaunere" <hans not junk at nyphp.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
X-BeenThere: talk at lists.nyphp.org
X-Mailman-Version: 2.1.2
Precedence: list
Reply-To: NYPHP Talk <talk at lists.nyphp.org>
List-Id: NYPHP Talk <talk.lists.nyphp.org>
List-Unsubscribe: <http://lists.nyphp.org/mailman/listinfo/talk>,
<mailto:talk-request at lists.nyphp.org?subject=unsubscribe>
List-Archive: <http://lists.nyphp.org/pipermail/talk>
List-Post: <mailto:talk at lists.nyphp.org>
List-Help: <mailto:talk-request at lists.nyphp.org?subject=help>
List-Subscribe: <http://lists.nyphp.org/mailman/listinfo/talk>,
<mailto:talk-request at lists.nyphp.org?subject=subscribe>
X-List-Received-Date: Wed, 14 Jan 2004 15:35:20 -0000
> This list is excellent and I follow it with great pleasure.=20
> But unfortunately, this is one of the list I am on that have the worst
> netiquette regarding quoting. Can I humbly advice to be gentle to
others list=20
Granted, it can be bad, but I've seen some pretty bad quoting on other
lists :)
> members and trim your quotes only to what is relevant in the message
you're are replying.
Certainly valid... good quoting and email forming is critical. And, as
clew takes shape and moves in to replace this system, messages *must* be
well formed.
We've been needing to get some posting guidelines and do's/don't's for
the NYPHP lists. If anyone has any written up, I'll be happy to add
them to nyphp.org
H
>From hans not junk at nyphp.com Wed Jan 14 10:39:04 2004
Return-Path: <hans not junk at nyphp.com>
Received: from ehost011-1.exch011.intermedia.net (unknown [64.78.21.3])
by virtu.nyphp.org (Postfix) with ESMTP id 5A2F7A85A6
for <talk at lists.nyphp.org>; Wed, 14 Jan 2004 10:39:04 -0500 (EST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: RE: [nycphp-talk] mysql + 0 rows affected error
Date: Wed, 14 Jan 2004 07:39:02 -0800
Message-ID: <41EE526EC2D3C74286415780D3BA9F87374BD9 at ehost011-1.exch011.intermedia.net>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: [nycphp-talk] mysql + 0 rows affected error
Thread-Index: AcPZUmq7+EdpGi4vR426jbqw54rEHwBYdHxg
From: "Hans Zaunere" <hans not junk at nyphp.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
X-BeenThere: talk at lists.nyphp.org
X-Mailman-Version: 2.1.2
Precedence: list
Reply-To: NYPHP Talk <talk at lists.nyphp.org>
List-Id: NYPHP Talk <talk.lists.nyphp.org>
List-Unsubscribe: <http://lists.nyphp.org/mailman/listinfo/talk>,
<mailto:talk-request at lists.nyphp.org?subject=unsubscribe>
List-Archive: <http://lists.nyphp.org/pipermail/talk>
List-Post: <mailto:talk at lists.nyphp.org>
List-Help: <mailto:talk-request at lists.nyphp.org?subject=help>
List-Subscribe: <http://lists.nyphp.org/mailman/listinfo/talk>,
<mailto:talk-request at lists.nyphp.org?subject=subscribe>
X-List-Received-Date: Wed, 14 Jan 2004 15:39:04 -0000
> i am wondering if this is a client/server incompatibility=20
> issue or not, maybe someone has had the same issue ... when connected
to=20
> mysql cli and performing an update or delete on a table i seem to
always get "0 rows
> affected" in which the case is not true (confirmed by a followed
select) ...
Are you affecting all rows in the table? Is a WHERE clause specified?
Otherwise, maybe the cli and server versions are incompatible...
H
>From hans not junk at nyphp.com Wed Jan 14 10:42:48 2004
Return-Path: <hans not junk at nyphp.com>
Received: from ehost011-1.exch011.intermedia.net (unknown [64.78.21.3])
by virtu.nyphp.org (Postfix) with ESMTP id 160FCA85A6
for <talk at lists.nyphp.org>; Wed, 14 Jan 2004 10:42:48 -0500 (EST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: RE: [nycphp-talk] php ncurses based mysql process watcher.. (preview)
Date: Wed, 14 Jan 2004 07:42:46 -0800
Message-ID: <41EE526EC2D3C74286415780D3BA9F87374BDB at ehost011-1.exch011.intermedia.net>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: [nycphp-talk] php ncurses based mysql process watcher.. (preview)
Thread-Index: AcPYeOvYpZv9IoRGRUyHKR8uW4evpwCO+crA
From: "Hans Zaunere" <hans not junk at nyphp.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
X-BeenThere: talk at lists.nyphp.org
X-Mailman-Version: 2.1.2
Precedence: list
Reply-To: NYPHP Talk <talk at lists.nyphp.org>
List-Id: NYPHP Talk <talk.lists.nyphp.org>
List-Unsubscribe: <http://lists.nyphp.org/mailman/listinfo/talk>,
<mailto:talk-request at lists.nyphp.org?subject=unsubscribe>
List-Archive: <http://lists.nyphp.org/pipermail/talk>
List-Post: <mailto:talk at lists.nyphp.org>
List-Help: <mailto:talk-request at lists.nyphp.org?subject=help>
List-Subscribe: <http://lists.nyphp.org/mailman/listinfo/talk>,
<mailto:talk-request at lists.nyphp.org?subject=subscribe>
X-List-Received-Date: Wed, 14 Jan 2004 15:42:48 -0000
> Hi Hans,
> Yea, that is me, just moved here to Manhattan from New Orleans (prior
Welcome to NYC.
> from the west coast). Found this list and am pretty excited=20
> about it as a php group in nola consists of a few guys sitting at a
bar chatting
> about what can be done in the language.
Not really that much different here...
> Anyway, if any of you are going to the Linux Expo at the Javitz center
> (Jan 21st-23rd) you will be able to find me there.
We sure are... http://nyphp.org/content/linuxworld/
Hope you can stop by the booth.
> Mview will be released from one of my servers located in our=20
> New Orleans data center as per the restrictions for source control (it
is part of
> the deal in being able to opensource a project from my work). It is
> already a tool that I always keep running here and most people at my
> work are running throughout the day to see the realtime graphs of the
> mysql servers.
>=20
> I am looking at a two week or so timeframe to be able to=20
> opensource the project.=20
If you want to show the app off at LinuxWorld, you're welcomed to use
our booth.
> I am currently working on a version that uses lines for the graphs
> instead of ascii. And hopefully can get a color-spread in so that it
> varies from blue to red etc..=20
>=20
> It looks cool and serves a purpose.
Looking forward to using it.
H
---
Hans Zaunere
President
http://nyphp.com
More information about the talk
mailing list