如何通过脚本php保存许多图像

时间:2014-02-12 10:41:55

标签: php android

在我的app android中,我用android相机拍照,然后通过这个脚本PHP将这些照片发送到PC:

<?php
 $base=$_REQUEST['image'];
 $binary=base64_decode($base);
 header('Content-Type: bitmap; charset=utf-8');
 $file = fopen('uploaded_image.jpg', 'wb');
 fwrite($file, $binary);
 fclose($file);
 echo 'Image upload complete!!, Please check your php file directory……';

&GT;

我正确地将照片发送到我的电脑,但是当我发送另一张照片时,这会覆盖上一张照片。因为名称(“uploaded_image.jpg”)是相同的。 可以指定不同的名称,以便保存所有照片吗?

2 个答案:

答案 0 :(得分:0)

您每次都可以使用uniqid创建唯一的文件名

$fileName = uniqid().'.jpg';
$file = fopen($fileName , 'wb');

答案 1 :(得分:0)

你可以使用PHP time()函数。它会添加带照片名​​称的时间戳。

$file = fopen(time().'uploaded_image.jpg', 'wb');


<?php
 $base=$_REQUEST['image'];
 $binary=base64_decode($base);
 header('Content-Type: bitmap; charset=utf-8');
 $file = fopen(time().'uploaded_image.jpg', 'wb');
 fwrite($file, $binary);
 fclose($file);
 echo 'Image upload complete!!, Please check your php file directory……';
  ?>