0

Is there any way that I can send images via my JSON Webservice?

Here is my code which looks for new images in a specific folder and return some data including (path, id which is the name of image file and the creation time of the file):

function getAllNewPhotos($lastCHK) {

    $dirPath = 'c:\my_images';
    $files1 = scandir($dirPath);
    $files = array_diff($files1, array('.', '..'));
    $newFiles = array();
    foreach ($files as $file) {
        $createTime = filectime($dirPath . '/' . $file);
        $path_data = pathinfo($dirPath . '/' . $file);          
                if ($createTime > $lastCHK) {
                    $newFiles[] = array(
                        'path' => $dirPath . '\\' . $file,                            
                        'ID' => $path_data['filename'],         
                        'dateImagAdded' => date('Y-m-d H:i:s', $createTime),
                    );
                }

    }
    return ($newFiles);
}

Is there any way to send the real image along with the other data which I have already passed?

If you need more clarification, please let me know which part you need more clarification.

Thanks

user385729
  • 1,924
  • 9
  • 29
  • 42
  • I think by JSON isn't possible, maybe by other methods: [stackoverflow: receive-image-data-as-json-and-injecting-it-into-the-dom][1] [1]: http://stackoverflow.com/questions/5000710/receive-image-data-as-json-and-injecting-it-into-the-dom – Bermudillo Nov 04 '13 at 21:04
  • 1
    You can base 64 encode it ... http://stackoverflow.com/a/13758760/2602732 – cmorrissey Nov 04 '13 at 21:10

1 Answers1

0

You can use base64 to encode your image

$imagedata = file_get_contents("/path/to/image.jpg");
             // alternatively specify an URL, if PHP settings allow
$base64 = base64_encode($imagedata);
ghost124
  • 1
  • 1