繁体   English   中英

将图像上传到localhost中的其他文件夹

[英]Uploading images to different folders in 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代码吗?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM