By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,051 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,051 IT Pros & Developers. It's quick & easy.

Filetype filter help needed.

aestheticmind
P: 2
Hello,
How do you evaluate multiple values in a single Variable? Can someone give me a hand on how to set $filter so that it will evaluate all of the values. Right now it will only eval the first one. Any help would be greatly appreciated. Thanks!


[PHP]<?php
// set filetype filter
$filter ="image/gif"xor"image/jpeg"xor"text/pdf"xor"application/word";

// get attachent data
$attachment = $_FILES['attachment']['tmp_name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment_name = $_FILES['attachment']['name'];
if ($attachment_type!==$filter) {
$attachment_type=die("Sorry Charlie");
} else {
echo "We have a Winner";
}
?>[/PHP]
Feb 8 '07 #1
Share this Question
Share on Google+
2 Replies


Nert
P: 64
Hello,
How do you evaluate multiple values in a single Variable? Can someone give me a hand on how to set $filter so that it will evaluate all of the values. Right now it will only eval the first one. Any help would be greatly appreciated. Thanks!


[PHP]<?php
// set filetype filter
$filter ="image/gif"xor"image/jpeg"xor"text/pdf"xor"application/word";

// get attachent data
$attachment = $_FILES['attachment']['tmp_name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment_name = $_FILES['attachment']['name'];
if ($attachment_type!==$filter) {
$attachment_type=die("Sorry Charlie");
} else {
echo "We have a Winner";
}
?>[/PHP]
hi aestheticmind,

You can use the array(), just put all the values you're filtering in an array, then use the function in_array() to check whether the value is in the array().

Like this example.
[PHP]
<?php
if(isset($_FILES['attachment'])){
$filter = array("image/gif", "image/jpeg", "text/pdf", "application/msword");

$attachment = $_FILES['attachment']['tmp_name'];

$attachment_type = $_FILES['attachment']['type'];

$attachment_name = $_FILES['attachment']['name'];

if (!in_array($attachment_type, $filter)) {
$attachment_type=die("Sorry Charlie");
} else {
echo "We have a Winner";
}
}
?>
[/PHP]

--nert (^_^)
Feb 8 '07 #2

aestheticmind
P: 2
Great answer. Thanks for the very useful help.

aestheticmind
Feb 8 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.