Anybody please help me! The function always return false although file extension is supported. Here my code;
[PHP]function checkExtension($extension)
{
$valid_ext = array('3gp','aac','avi','bmp','doc','flv','gif','g z','gzip','jpeg','jpg','mov','mp3','mpeg','mpg','p df','png','ppt','rar','tar','tif','txt','wav','wmv ','zip');
foreach($valid_ext as $ext)
{
if($extension==$ext)
{
return true;
break;
}
else
{
return false;
}
}
}
if(!checkExtension('doc'))
{
echo 'File not suppoted!';
}
else
{
echo 'File supported!';
}[/PHP]
2 1701
it's ok i have been got the solution by using in_array function as shown below;
[PHP]$valid_ext = array('3gp','aac','avi','bmp','doc','flv','gif','g z','gzip','jpeg','jpg','mov','mp3','mpeg','mpg','p df','png','ppt','rar','tar','tif','txt','wav','wmv ','zip');
if(!in_array('abc',$valid_ext))
{
echo 'File not supported!';
}
else
{
echo 'File supported!';
}[/PHP]
Heya, Adam.
A more elegant and efficient solution: -
$_validExtensions =
-
array
-
(
-
'3gp' => true,
-
'aac' => true,
-
.
-
.
-
.
-
);
-
-
return ( ! empty($_validExtensions[$ext]) );
-
Searching an array by value takes O(n), whereas searching by key takes O(1)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Philip D Heady |
last post by:
Ok, here's my code. Can't get it to check file extension properly or file
size...had it working before but not sure why it's buggy now.
} elseif ($photo) {
$ext = strtolower(substr($photo,...
|
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my...
|
by: Biffo |
last post by:
I have PHP Version 5.0.3 installed on Windows XP Pro with IIS as the
webserver. All is working well, except I get a -
Fatal error: Call to undefined function mssql_connect() in...
|
by: Puzzled |
last post by:
This is a weird problem, but perhaps someone else has seen it before
(I hope!)
If I use a fully qualified include call
include ( 'http://localhost/subtree/filename.php')
I get an 'undefined...
|
by: drewmania001 |
last post by:
i've read various info on the web including the following
http://php.mirrors.ilisys.com.au/manual/en/ref.mysqli.php
mySQL Version 4.1.16
PHP Version 5.1.2
with Zend Engine v2.1.0
OS Windows...
|
by: adamjblakey |
last post by:
Hi,
I want to convert this into a function. How would i go about doing this?
$path_thumbs = "images/thumbs";
$path_big = "images/big";
//the new width of the resized image....
|
by: adamjblakey |
last post by:
Hi,
I am trying to build a function and from a script but it does not seem to be working. Can anyone see anything wrong with this?
Also i need it to convert the large image to a specific size...
|
by: Chris Rebert |
last post by:
On Sat, Sep 27, 2008 at 3:42 PM, Michael Crute <mcrute@gmail.comwrote:
Looking at the docs for the mimetypes module, it just guesses based on
the filename (and extension), not the actual contents...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |