【发布时间】:2016-04-11 10:06:03
【问题描述】:
在 Propriete 实体中,我有 5 个字段称为 image1 image2 image3 image4 image5
我不想在 for 循环中添加这些字段
我试过了,但它不起作用:
for($i=0;$i<count($this->request->data['files'])&&$i<5;$i++){
//... some code
$propriete->{'image'.$i+1} = $file['name'];
}
}
有人可以帮我吗?
编辑
这是我的循环代码:
for($i=0; $i<count($this->request->data['files']) && $i<5; $i++){
$file=$this->request->data['files'][$i];
$ext = substr(strtolower(strrchr($file['name'], '.')), 1); //get the extension
$arr_ext = array('jpg', 'jpeg', 'gif'); //set allowed extensions
if(in_array($ext, $arr_ext))
{
//do the actual uploading of the file. First arg is the tmp name, second arg is
//where we are putting it
move_uploaded_file($file['tmp_name'], WWW_ROOT . '/img/' . $file['name']);
debug($file['name']);
//prepare the filename for database entry
$propriete->{'image'.$i+1} = $file['name'];
}
}
【问题讨论】:
-
$file['name']没有意义,请显示足够的代码来解释这个变量的来源 -
@RiggsFolly 检查编辑
-
你能指定错误出现在哪一行吗?是 $propriete->{'image'.$i+1} = $file['name'];你没有得到文件名吗?或者无法在对象属性中设置文件名
-
那么实际的问题是什么但它不起作用对我们没有多大帮助
-
问题是$prorpete->image1 return null
标签: php