Beranda > osTicket > Menampilkan Lampiran Gambar di osTicket v1.6 RC5

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>&nbsp;(<i>$size</i>)&nbsp;&nbsp;";
            }
        }
        return ($attachstr);
    }
  • Share/Bookmark
691 kali dibaca Cetak Artikel Ini Cetak Artikel Ini

  1. DaSilva
    5 November 2009 pada 6:56 | #1

    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%?

  2. 5 November 2009 pada 9:29 | #2

    @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.

  3. DaSilva
    6 November 2009 pada 7:28 | #3

    Thanks, it works like a charm! :)

  4. 6 November 2009 pada 8:11 | #4

    You’re welcome. I am so glad it works fine at yours. :-)

  5. batman
    4 Januari 2010 pada 19:45 | #5

    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

  6. batman
    4 Januari 2010 pada 19:51 | #6

    Happy New Year 2010 in the France

  7. 6 Januari 2010 pada 11:50 | #7

    @batman

    Happy New Year 2010 too for you from Indonesia. :-)

  8. Steven Nolting
    31 Juli 2010 pada 10:29 | #8

    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

  9. 3 Agustus 2010 pada 22:21 | #9

    @Steven Nolting

    What is the URL you were currently using when you got that error?

  10. Marc
    24 Agustus 2010 pada 19:03 | #10

    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

  11. Benjamin
    8 September 2010 pada 13:13 | #11

    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.

  1. Belum ada tautan balik