I was interested with one of the topic in osTicket Discussion Forum about how to display the image attachment which its extention such as: jpg, gif, png, and bmp directly on the browser, then I made another modification which will automatically detect the URL and the directory name where the attachments file located. This code will work, with assuming: the sub directory for your attachment files located one level under the main directory of your osTicket. For example: your osTicket installed in “support” directory, whereas the attachment file located one level under the “support” directory, with named: “attachment”. This modification will also automatically resize the image width if it is greater than the maximum of osTicket width area on viewticket page. We assume that the maximum ticket width is 820 pixels (based on its css file).
Open your \include\class.ticket.php file, and find the getAttachmentStr function, then replace all code of its function become like this:
// Modified by Masino Sinaga, last updated: November 5, 2009 // in order to display image properly inside the ticket area // especially if the image's width greater than 820 px, then // resize the image's width maximum to 820 px. function getAttachmentStr($refid,$type){ global $cfg; $helpdesk_url=$cfg->getUrl(); $dir=$cfg->getUploadDir(); $dir = preg_replace("/\\\\/","/",$dir); $dir = explode('/', $dir); $arrDir = array_reverse($dir); $dir = $arrDir[0]; $sql ='SELECT attach_id,file_size,file_name,file_key FROM '.TICKET_ATTACHMENT_TABLE. ' WHERE deleted=0 AND ticket_id='.db_input($this->getId()).' AND ref_id='.db_input($refid).' AND ref_type='.db_input($type); $res=db_query($sql); if($res && db_num_rows($res)){ while(list($id,$size,$name,$key)=db_fetch_row($res)){ $hash=MD5($this->getId()*$refid.session_id()); $size=Format::file_size($size); $ext = strtolower(substr(strrchr($name, '.'), 1)); $fullfilename = $helpdesk_url.$dir.'/'.$key.'_'.$name; if (in_array($ext,array('jpg', 'png', 'gif', 'bmp'))) { list($width, $height, $type, $attr) = getimagesize($fullfilename); if ($width > 820) { $attachstr.= '<p align="center"><a href="'.$fullfilename.'" target="_blank"><img src="'.$fullfilename.'" width="820"/></a></p><br />'; } else { $attachstr.= '<p align="center"><a href="'.$fullfilename.'" target="_blank"><img src="'.$fullfilename.'" /></a></p><br />'; } } $attachstr.= "<a class='Icon file' href='attachment.php?id=$id&ref=$hash' target='_blank'><b>$name</b></a> (<i>$size</i>) "; } } return ($attachstr); }

Is it possible to display it inside of the ticket but if the image is bigger than the width of the osTicket template layout it should be resized to this size and after a click on it you can view it in a new window in 100%?
@DaSilva
Yes, it is. I have modified that original function above with the latest version today, a few minutes before I sent this comment. Please try to replace the old one with this new one (see above). Hopefully this will help you. Thanks.
Thanks, it works like a charm!
You’re welcome. I am so glad it works fine at yours.
Hello, thank you for all these codes.
I try if possible to open other files (. doc,. … pdf)
adding an additional line?
Thank you for a solution …
Arnaud
Happy New Year 2010 in the France
@batman
Happy New Year 2010 too for you from Indonesia.
Masino
I have implemented many of your mods. Most have been successful. I have a nagging problem, when I try to update an existing ticket I receive “errors occurred try again”. Is their something I need to be looking at to trace down the error. I know this is vague but any help would be greatly appreciated. You have written some great mods. Keep up the great work.
Respectfully
Steve Nolting
@Steven Nolting
What is the URL you were currently using when you got that error?
All my attachments are stored in support/attachments/”monthyear” subdir
Therefore my attachments are not shown. Is there a way to change the code to take in to account the various subdirs that exist ?
or where can i change the PHP code to not create subdirs when recieving/uploading attachments ?
As you can see from my questions here PHP is not my thingie ..
Hopefully someone can point me in the right direction
Same here like Marc – there must be a change in the code.
Any help? Also my suggestion is, to implement such a thing like lightbox, this is way nicer than open a new browser window.
Hello Masino
Thank you for your tireless efforts.
However, I have the same problem as Marc. When a customer uploads an image it will appear in my admin panel. When i upload an image in the admin panel it is not visible there.
Background are two different locations.
If the customer uploads: .. / attach / *. jpg
If the supporter uploads: .. / attach / MMYY / *. jpg (MM for the month and YY is the year)
you miss the line: (I put it somewhere above $fullfilename and below while)
$month=date(‘my’,strtotime($this->getCreateDate()));
the code in the Attachment folder stands for date:my (month year)
also change this line adding the $month and problem fixed.
$fullfilename = $helpdesk_url.$dir.’/’.$month.’/’.$key.’_’.$name;
Hello At once I want apologize my English. The problem:
Your MOD is successfully running on my local server. But at work does not want. Getimagesize function does not get the size of the image. I made a Display the echo:
echo $width; There is no image width is displayed. Do not tell me what could be the problem? In this case the image itself can be seen in the response. Based on the fact that the value is not passed, the end result is the same can not be displayed in the format of 820 width. The image is inserted with the baseline values.