2016-03-12 34 views
1

因此我可以將我的照片從我的Android應用程序上傳到/var/www/html/ProductPhotos但是,當我想要獲取產品的名稱並將其用作新的目錄和圖像名稱,然後它不工作。我創建了新的目錄,並帶有777權限(即使其超級不好)創建新目錄和/var/www/html/ProductPhotos,但現在它是我所需要的。這裏是我的PHP代碼:將圖像存儲在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); 

?> 
+0

工作!謝謝!也把它作爲答案,所以我可以給你信用 –

+0

完成+添加我的2美分 – Terminus

回答

0

您使用逗號而不是句號。而你錯過了一個斜線。

file_put_contents("/var/www/html/ProductPhotos/" . $ProductAccountName . "/" . $ProductName . ".JPG", $DecodedProductImage);` 

file_put_contents docs.

您可能要付諸實施,一些檢查,以確保用戶不使用相對路徑(../使用作爲一部分ProductAccountName,例如)。只要注意用戶使用它來做惡意的事情。

+0

謝謝!生病了看着它 –

相關問題