【问题标题】:Adding an image to a JSON WebService -PHP将图像添加到 JSON WebService -PHP
【发布时间】:2014-10-08 20:07:56
【问题描述】:

有什么方法可以通过我的 JSON Web 服务发送图像?

这是我的代码,它在特定文件夹中查找新图像并返回一些数据,包括(路径、id 是图像文件的名称和文件的创建时间):

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);
}

有什么方法可以将真实图像与我已经传递的其他数据一起发送?

如果您需要更多说明,请告诉我您需要更多说明的部分。

谢谢

【问题讨论】:

标签: php json web-services


【解决方案1】:

您可以使用 base64 对图像进行编码

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

【讨论】:

    猜你喜欢
    • 2011-09-28
    • 2023-03-06
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多