Menampilkan Lampiran Gambar di osTicket v1.6 RC5
Saya tertarik dengan salah satu topik di Forum Diskusi osTicket mengenai bagaimana menampilkan lampiran gambar di mana ekstensi file tersebut seperti: jpg, gif, png secara langsung di browser, maka saya memutuskan untuk membuat modifikasi lainnya yang akan otomatis mendeteksi URL dan nama sub direktori di mana file-file lampiran tersimpan. Kode hasil modifikasi ini berfungsi dengan baik, dengan asumsi: sub direktori untuk file-file lampiran berada satu level di bawah direktori utama dari osTicket Anda. Contoh: osTicket Anda diinstall di dalam direktori “support”, dan file-file lampiran berada satu level di bawah direktori “support” tadi yang bernama “attachment”. Modifikasi ini juga otomatis menyesuaikan ukuran lebar gambar jika melebihi lebar maksium area tiket pada halaman viewticket. Kita mengasumsikan bahwa lebar maksimal area tiket adalah 820 pixels (berdasarkan pada file css-nya).
Buka file \include\class.ticket.php, lalu cari function yang bernama getAttachmentStr, lalu timpa semua kode di function tersebut menjadi seperti berikut:
// 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); }
Cetak Artikel Ini



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.