0

I am trying to get Image from FTP server and print it afterwards without saving it locally. My problem is, that the image is in some kind of crypted form probably, or in Binary, honestly I have no idea.

This is a code I do have so far:

public function getImagePreview($imageName){
  if(ftp_get($this->connection, "php://output", "web/media/images/".$imageName, FTP_BINARY)){
    $data = ob_get_contents();
    $dataSize =  ob_get_length();
    ob_end_clean();
    return array('data' => $data, 'size' => $dataSize);
  }else{
    return false;
  }
}

It's a method inside one object that I am calling from a file and here is a the code I am trying to show the image.

This line is for getting the Image (calling the function above), but it's a different PHP file! This is a view file.

require_once "../objects/ftpm.php";
$ftpM = new FTPManager();
$image = $ftpM->getImagePreview($imageName);

And here I am trying to print the image.

<span> Preview </span>
<img class="materialboxed" width="650" src="<?php echo $image["data"]; ?>"/>

But it actually shows tons of this code (I showed only a few lines as an example, since it's so extremely long):

����JFIFdd��Duckyd��Adobed������Ul��� u!"1A2# QBa$3Rq�b�%C���&4r ��5'�S6��DTsEF7Gc(UVW�����d�t��e�����)8f�u*9:HIJXYZghijvwxyz�������������������������������������������������������m!1"AQ2aqB�#�R�b3 �$��Cr��4%�ScD�&5T6Ed' s��Ft����UeuV7��������)��������������(GWf8v��������gw��������HXhx��������9IYiy��������:JZjz����������?��ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׈�ߺ�Pq�uHRh����<��fV��(�u ���nG�u�Tb��?��1g�,�Q�9g��6GԼ����ӌ��X J��G���4�abk>�׺F�b1��ޖ��x%w>$y�{�M]^���UZ�Kma��{��^�><���VX�y����4���V�p?�׺GɆ��^3L�gO4_s5���B���7�[���u�|B���&a���l�nm��׺s��E-%�ԽEi�-<2��2�b5����-� {�^�=}3:�WQhjVL�[PY��Y�bC�JX����y����i*�Ӗ�2�t�GD�e Dͨ$r�K�r\X}8�^�W�� jI�"��,ji|0$S�U��J��.�R�H��}��t���-fBi�.6����$��b�+{\���~��a�����%:����Y�$���9U�}���Ҷ�YVq�Z�ɞ9�xPL嘆q�r��p-��{�,\k5��3�KG�!��Le�Ą����׺�b�/S 4�ߠ�#i�d�ԓoΛ{�^�g���>@�9$8��:CH�jF$��*)��u�Q�}��t#����F���2:0ee?B� ~��r��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^��׽��u�~��{ߺ�^ c�>�׺Bg6.�ԤoGY&�ii�B��RD��f-� ?�}��t϶Z�-F��;kI�j����7��\�ԅmc�C��׺?B�K)"�a��a��u�r �h�r��,�,�_+k*�O��{�^���MU5\��4�G��+ Y�+1C�������{���t��]K�k�X��L�e(�uCq~��$1{*��_���_S�����䶩N���>���׺VIG�����L�J���Sn8���{��L��w�'��2��hb���2<�8b��rH7~m��{��^K�f�/�䤍i*8Y����#��ʗck)��>�׺a�9s9�Zq9ZX�Q���o!���j &�U��I��6ߺ�K��0�S�]T�jii֊/�>o=\�-eBO�_�{�=NRz$�t����5%|�J)�����J,����X�#�����{�/%OY����� rX(Q�b=��t��N�I;F�Lg���6�@��e]Ib����/��{��E�Ʀ@�1hI"G���44�T�A��������׺k�����(��\R�Z2Y������>�o��{�^�7SUG)ED2���&���F�l�^_�z�U��׺*j�)�h�����2����#��� e1�Z����=��t1�I�|5-VJ�9ni%�Ti$Q��X��UTF����~~��׺Y���WӭM$�OM��&���c��0������~��4U;N�^$E{8

Thank you for any help!

Jan Kočvara
  • 81
  • 10

1 Answers1

0
$ftpM = new FTPManager();
$image = $ftpM->getImagePreview($imageName);
$type = 'jpeg'; // file type here
header("content-type: image/{$type}");
echo $image['data'];