我想保存一個多輸入文件,我是從窗體接收的。但結構不是我所期望的...這裏是結構:CakePhp上傳多個圖像
Array
(
[files] => Array
(
[name] => Array
(
[0] => 25th birthday.PNG
[1] => 1535UDEM-info-2011.jpg
[2] => 2012-06-11 14.49.48.jpg
[3] =>
)
[type] => Array
(
[0] => image/png
[1] => image/jpeg
[2] => image/jpeg
[3] =>
)
[tmp_name] => Array
(
[0] => /tmp/php0GW7d6
[1] => /tmp/phpwzS0DO
[2] => /tmp/phpMifC4w
[3] =>
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 4
)
[size] => Array
(
[0] => 159487
[1] => 528765
[2] => 822193
[3] => 0
)
)
)
可cakephp保存這種類型的數組?如果是這樣,怎麼樣?我使用這個插件http://cakephp-upload.readthedocs.org上傳圖片。我想我必須一個一個拯救,但我不知道如何。林試圖重新命名每個圖像與此代碼:
foreach ($imageFiles['name'] as $key => $value) {
if(!empty($value))
{
$file = $imageFiles['url']; //put the data into a var for easy use
$ext = substr(strtolower(strrchr($file['name'], '.')), 1); //get the extension
$randomCode = substr(md5(uniqid(rand(), true)), 5, 5);
$imageFiles['url']['name'] = date('Y-m-d')."_".$randomCode.".".$ext;
} else {
$imageFiles['url'] = "";
}
}
有人可以給我建議如何做到這一點?
這是一個評論,不是答案也不會這可能解決他與多個文件的問題在一個非常CakePHPish方式。事實上,大多數上傳者的PHP腳本吸收,因爲他們被認爲是例子。 – burzum 2015-03-24 23:46:18