Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Attachment via API, using PHP

Hello, 

I did as in the demo: 

#  Originally authored by jared@osTicket.com
#  Modified by ntozier@osTicket / tmib.net
#  Attachments fixed by ddhnote@gmail.com

but I get HTTP code 404 ( if I ignore the attachment option, all is good ) 

Please advice, 
Daniel 

Comments

  • 404 means not found.  Sounds like your script could not find the attachment.
  • Thanks for replying. 
    To respond:  

    Don't think so, because when I use: 

    'data:audio/mpeg;base64,' . base64_encode(file_get_contents('/path/to/attachment.mp3')),

    without the word "data" it attaches the encoded string ( a very long one )

    The path checks out. The file is there. What am I missing? 

    Please advice, 
    Daniel 
  • Hello All, 

    We fixed it. For us the problem was the XSS forgery protection and PCI DSS protection.

    In the demo example we've added for post:

    encoded_data = base64_encode(json_encode($data));


    And in the osTicket files: include/class.api.php we've replaced:

    $decoded_data = parent::parse($stream);   with:   $decoded_data = $this->base64_parse($stream);

    and added:

    function base64_parse($stream) {
            if (is_resource($stream)) {
                $contents = '';
                while (!feof($stream))
                    $contents .= fread($stream, 8192);
            } else
                $contents = $stream;
            return json_decode(base64_decode($contents), true);
        }


    Thanks. I hope you find this useful. 
Sign In or Register to comment.