![](/img/trans.png)
[英]Warning: getimagesize(image.jpg) [ ]: failed to open stream: no such file or directory
[英]Upload images in directory specific to name like /i/m/image.jpg
我正在將圖像上傳到服務器上的目錄/media/catalog/product
那么它將采用圖像的第一個字符並將其放置在與該字符匹配的目錄中(如果不存在,還需要創建目錄)然后對第二個字符執行相同的操作。
例如,如果我上傳一個名為product.jpg
的圖像,它將最終位於目錄/media/catalog/product/p/r/
test.jpg
> /media/catalog/product/t/e/
這些圖像都在我計算機的一個文件夾中,或者我可以將它們全部上傳到一個目錄中。
我正在嘗試使用Magento 1.9版執行此操作
<?PHP
/* TRANSFORM FILES ARRAY */
function diverse_array($vector) {
$result = array();
foreach($vector as $key1 => $value1)
foreach($value1 as $key2 => $value2)
$result[$key2][$key1] = $value2;
return $result;
}
/* DO THE TRANSFORMATION, warning key for the superglobal $_FILES may be "picture" */
$upload = diverse_array($_FILES["upload"]);
/* create folder if not exists and then move file to the right folder */
foreach($upload as $current)
{
mkdir("/media/catalog/product/" . $current["name"][0]);
mkdir("/media/catalog/product/" . $current["name"][0] . "/" . $current["name"][1]);
move_uploaded_file($current["tmp_name"],
"media/catalog/product/" . $current["name"][0] . "/" . $current["name"][1] . "/" . $current["name"]);
}
請注意,您可能想更改目錄的權限,請參見mkdir manual ,並檢查輸入文件的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.