Jump to content

Help WIth An Array


refiking

Recommended Posts

I want to have an array of extension types that are acceptable.  Currently, the method I am using will only allow me to check 1.  What should I do differently?

 

$ext = substr($file_name, strrpos($file_name, '.') + 1);
if($ext != 'jpg'){ 
$exterror++; 
}
if($exterror > 0){
    echo "Error:File type not supported.";
    return;
}

Link to comment
https://forums.phpfreaks.com/topic/205904-help-with-an-array/
Share on other sites

try this:

 

$ext_array("jpg", "png"); // so on and so forth
$ext = substr($file_name, strrpos($file_name, '.') + 1);
if(!in_array($ext, $ext_array)){ 
$exterror++; 
}
if($exterror > 0){
    echo "Error:File type not supported.";
    return;
}

 

hope this helps.

 

bluejay,

Link to comment
https://forums.phpfreaks.com/topic/205904-help-with-an-array/#findComment-1077476
Share on other sites

@projectFear:

well, its not entirely my code. I just assume his code were correct and added my code on it. I'm kinda lazy writing a new code over something that the user didn't complained about.  ;)

 

True enough, but hopefully the OP can look at modified (and cleaned) code and see any improvements (or maybe it got worse).

Link to comment
https://forums.phpfreaks.com/topic/205904-help-with-an-array/#findComment-1077649
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.