Checking if link to file exist

QuestionsChecking if link to file exist
Cedric asked 5 years ago


I am using the paid version.

here a sample of my code

$col = array();
$col[“title”] = “FILE_NAME”;
$col[“name”] = “path”;
$col[“width”] = “100”;
$col[“default”] = “<a target=’_blank’ href=’/files/msds/{path}’><img src=’../../datagrid/images/mimetypes/pdf.png’ alt=’pdf’ width=’16’ height=’16’></a>”;
$cols[] = $col;

This works fine.

I would like to know if there is a way to check if the file exist within the grid. and display another logo is it does not exist.


1 Answers
Abu Ghufran Staff answered 5 years ago
Instead of 'default' property, you can use on_data_display event. Code will be like following:
Refer demos/editing/file-upload.php line 118 for demo.

$col["on_data_display"] = array("display_icon","");
function display_icon($data)
	$path = $data["path"];
	if (file_exists("/files/msds/".$path))
		return "<a target='_blank' href='/files/msds/{$path}'><img src='../../datagrid/images/mimetypes/pdf.png' alt='pdf' width='16' height='16'></a>"
		return "<img src='../../datagrid/images/mimetypes/not-found.png' alt='pdf' width='16' height='16'>"
Abu Ghufran - Dev Team
Grid 4 PHP Framework
Your Answer

19 + 3 =

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?