如何发送上传的图像路径上的目录(web目录)到mysql.可以同时发送吗?


How to send uploaded image path on directory(web directory) into mysql?.Is it possible to send simultaneously?

这是我的php端,我的IDE是Android Studio.所以我能做些什么使名称和图像插入mysql从这里?

$name = $_POST["name"];
$image = $_POST["image"];
$decodedImage =base64_decode("$image");
file_put_contents("pictures/" . $name . ".JPG", $decodedImage);

详细说明IgnazioC注释,您可以生成图像名称,而不是使用用户提供的名称。

$name = $_POST["name"];
$image = $_POST["image"];
$decodedImage =base64_decode("$image");
$imageId = md5(microtime(true));
file_put_contents("pictures/" . $imageId . ".JPG", $decodedImage);

在此之后,您可以将$imageId变量保存在数据库中,并停止使用$name = $_POST["name"];,如果它没有正确处理,它可能是一个安全问题,因为我可以提供图像名称为../whateverfile.jpeg并从外部访问它。

另一个更详细的事情是,例如,将$imageId字符串分成2或3个字母的组,并用它们创建一个目录结构,然后保存图像。这将允许您避免每个文件夹的文件系统文件限制。