【发布时间】:2015-03-25 10:46:12
【问题描述】:
我正在尝试保存从表单接收到的多输入文件。但是结构不是我所期望的......这是结构:
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'] = "";
}
}
有人可以给我建议吗?
【问题讨论】:
标签: php cakephp image-uploading