file extension

Questionsfile extension
Benjamin asked 9 years ago


My DB field that contains the name of uploaded file is doc_file.
I need to get the extension of the file and tried this:

$ext = substr($row['doc_file'],-3);

and also …

$ext = substr($data['doc_file'],-3);

neither of them works … How can I do that ??


5 Answers
Benjamin answered 9 years ago

… I also tried this

$col["condition"] = array('substr({doc_file},-3) == "pdf"', $icone = "doc_pdf.png", $icone = "doc_office.png");

It doesn't work ! … can I use a php (substr) inside a condition ?


Abu Ghufran answered 9 years ago

Pasting from docs:

For extended conditional data, you can also have callback function, that will allow you to display based on row data. For e.g.

$col["on_data_display"] = array("display_keyword","");

function display_keyword($data)
$kw = $data["keyword_name"];
$numKeywords = count(explode("n",$pass));
if ($numKeywords > 3)
return $numKeywords." Keywords";
$pass = str_replace("+"," ",$pass);
return $pass;

Benjamin answered 9 years ago


I've already read this but didn't understand how it solve my problem … not clear for me.


Abu Ghufran answered 9 years ago

Not tested the code, but it would be something like:

$col["on_data_display"] = array("display_icon","");

function display_icon($data)
$file = $data["doc_file"];

if (substr($file,-3) == "pdf")
return "doc_pdf.png";
return "doc_office.png";

// it can also be: return "<img src='doc_office.png'>";

Benjamin answered 9 years ago

Hi Abu,

Thanks … I didn't understood to replace the "condition" by this …
It Works fine !

Thanks again

Your Answer

19 + 19 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?