Multiple File Icons

QuestionsMultiple File Icons
Matthew asked 7 years ago

Hi Abu,

Love the product and I just wanted to share some code. I had previously implemented displaying icons in the grid for uploaded files which worked well. I have now enabled the multiple file upload option and wanted to maintain the icon display feature, only this time display 1 icon per uploaded file. Here's the solution I came up with adding another array to your original solution:

function display_icon($data)
{
$filelist = $data["attachment"];
$filearray = explode(",",$filelist);
$filecount = count($filearray);
$result = "";
for($x=0; $x <= $filecount; $x++){
$file = $filearray[$x];
$arr = explode(".",$file);
$ext = $arr[count($arr)-1];
if (empty($file))
$result .= "";
else if (strtolower($ext) == "pdf")
$result .= "<a href="javascript:window.open('http://192.168.1.20/intranet/phpgridfull$upload_url/$file#page=1&zoom=75&#039;,'Title','width=800,height=900')">
<img height=30 src=http://192.168.1.20/intranet/phpgridfull/iconpdf.jpg></a>";
else if (strtolower($ext) == "doc" || strtolower($ext) == "docx")
$result .= "<a href="javascript:window.open('http://192.168.1.20/intranet/phpgridfull$upload_url/$file&#039;,'Title','width=800,height=900')">
<img height=30 src=http://192.168.1.20/intranet/phpgridfull/iconword.png></a>";
else if (strtolower($ext) == "xls" || strtolower($ext) == "xlsx")
$result .= "<a href="javascript:window.open('http://192.168.1.20/intranet/phpgridfull$upload_url/$file&#039;,'Title','width=800,height=900')">
<img height=30 src=http://192.168.1.20/intranet/phpgridfull/iconexcel.png></a>";
else if (strtolower($ext) == "png" || strtolower($ext) == "jpg" || strtolower($ext) == "jpeg")
$result .= "<span style='height:30px;width:30px;'><a class='fancybox' href='http://192.168.1.20/intranet/phpgridfull$upload_url/$file&#039; target='_blank'><img style='max-width:100%;max-height:100%;width:auto;height:auto;position:relative;top:50%;transform:translateY(-50%);' src='http://192.168.1.20/intranet/phpgridfull$upload_url/$file'></a></span>&quot;;
else if (strtolower($ext) == "tif")
$result .= "<a href="javascript:window.open('http://192.168.1.20/intranet/phpgridfull$upload_url/$file&#039;,'Title','width=800,height=900')">
<img height=30 src=http://192.168.1.20/intranet/phpgridfull/tif.gif></a>";
else
$result .= "<a href="javascript:window.open('http://192.168.1.20/intranet/phpgridfull$upload_url/$file&#039;,'Title','width=800,height=900')">
<img height=30 src='http://192.168.1.20/intranet/phpgridfull/iconunknown.png'>$file</a>&quot;;
}
return $result;
}

2 Answers
Abu Ghufran answered 7 years ago

Thats great. Thanks for sharing.
I'll review to incorporate this in demos.

Matthew answered 7 years ago

I've had to change the href links using this new method as the popup windows weren't working.

For PDF;

<a href="javascript:window.open('http://192.168.1.20/intranet/phpgridfull$upload_url/$file#page=1&zoom=75&#039;,'Title','width=800,height=900')">

For PNG, JPG, JPEG:

<a class='fancybox' href='http://192.168.1.20/intranet/phpgridfull$upload_url/$file&#039; target='_blank'><img style='max-width:100%;max-height:100%;width:auto;height:auto;position:relative;top:50%;transform:translateY(-50%);' src='http://192.168.1.20/intranet/phpgridfull$upload_url/$file'&gt;

Everything else:

<a href="http://192.168.1.20/intranet/phpgridfull$upload_url/$file"&gt;

Your Answer

9 + 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?