所以我可以将我的照片从我的Android应用程序上传到/var/www/html/ProductPhotos,但是当我想获取产品的名称并将其用作新目录的名称和图像名称时,它不起作用。我创建了具有 777 个权限的新目录和/var/www/html/ProductPhotos(即使它超级糟糕),但现在它是我需要的。这是我的PHP代码:
<?php
$ProductAccountName = $_POST['ProductAccountName'];
$ProductName = $_POST['ProductName'];
$ProductImage = $_POST['EncodedImage'];
$NewDirectory = "/var/www/html/ProductPhotos/" . $ProductAccountName;
mkdir($NewDirectory, 0777, true);
//$DecodedProductImage = base64_decode("$ProductImage");
//$ProductName = $ProductName .".JPG";
file_put_contents("/var/www/html/ProductPhotos/" . $ProductAccountName, $ProductName . ".JPG", $DecodedProductImage);
?>
您使用的是逗号而不是句点。而且你缺少一个斜杠。
file_put_contents("/var/www/html/ProductPhotos/" . $ProductAccountName . "/" . $ProductName . ".JPG", $DecodedProductImage);`
请参阅file_put_contents文档。
您可能希望进行一些检查,以确保用户不使用相对路径(使用 ../例如,作为产品帐户名称的一部分)。只是要小心用户使用它来做恶意的事情。