以php json形式从webservice上传多个图像

时间:2015-10-30 10:49:28

标签: php mysql arrays json

我正在使用php和json创建一个Web服务来上传多个图像 要在文件夹和数据库中移动,我可以使用此代码上传一个图像

        $image_binary=base64_decode($real_img);
        $image_file = fopen("images/real/".time().$real_img.$id.'.jpg', 'wb');
        fwrite($image_file, $image_binary); 
        $image_path = "".$id.'.jpg';
        move_uploaded_file(fwrite($image_file, $image_binary), $image_path);

如果我在阵列中获得多个图像,如何将此代码用于多个图像。

1 个答案:

答案 0 :(得分:0)

循环它: (另)

$images = array(0 => 'img1....jpg', 
                1 => 'img2....jpg');

uploadImages($images);

function uploadImages($images) {
    for($i = 0; count($images) > $i; $i++) {
        $image = $images[$i];

        $image_binary=base64_decode($image);
        $image_file = fopen("images/real/".time().$image.$id.'.jpg', 'wb');
        fwrite($image_file, $image_binary); 
        $image_path = "".$id.'.jpg';
        move_uploaded_file(fwrite($image_file, $image_binary), $image_path);
    }
}