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

1,800 kali dibacaCetak Artikel Ini Cetak Artikel Ini

Komentar

  1. DaSilva mengatakan:

    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. Masino Sinaga mengatakan:

    @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 mengatakan:

    Thanks, it works like a charm! :)

  4. Masino Sinaga mengatakan:

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

  5. batman mengatakan:

    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 mengatakan:

    Happy New Year 2010 in the France

  7. Masino Sinaga mengatakan:

    @batman

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

  8. Steven Nolting mengatakan:

    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. Masino Sinaga mengatakan:

    @Steven Nolting

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

  10. Marc mengatakan:

    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 mengatakan:

    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.

  12. Scirocco mengatakan:

    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)

  13. Steve mengatakan:

    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;

Utarakan pikiran Anda

*


*