2015-10-30 73 views
2

我使用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); 
上傳一張圖片

如何獲取數組中的多個圖像,如何將此代碼用於多個圖像。

+0

什麼是 「ID」?什麼是'$ real_image'?解釋更多。 –

+0

$ real_image是我得到的圖像的變量。 –

回答

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