将图像上载到localhost中的不同文件夹

时间:2016-05-06 12:54:42

标签: php android

我想将图像添加到图像/ localhost中:

  • 我应该对这个php脚本添加什么修改,这样我就可以为每个id添加一个文件夹(我想在同一个文件夹中发布具有相同Id的不同图像)

以下是用于上传图片的php文件:

<?php 
$name=$_POST["id"];
$image=$_POST["image"];
$decodedImage=base64_decode("$image");
file_put_contents("images/" . $name . "/" .$name . ".JPG" , $decodedImage);
?> 
  • 有没有其他方法可以添加多个图像而无需多次重复java代码?

1 个答案:

答案 0 :(得分:0)

在将文件上传到目录之前,请确保该目录存在。

$name=$_POST["id"];
$image=$_POST["image"];

if(!file_exists ( "images/" . $name )){
       mkdir("images/" . $name, 755);
}

$decodedImage=base64_decode("$image");
file_put_contents("images/" . $name . "/" .$name . ".JPG" , $decodedImage);