您好,我一直在探索在实现站点时使用框架 cakephp。在我当前的 PHP 脚本中,出现了这个错误:未定义的偏移量:1,它已经让我头疼了。你们能帮我解决我做错了什么吗?
我的代码在这里:
function file_upload($file_array, $id){
if(count($file_array))
{
$location = "files/library-files/";
foreach ($file_array as $file) {
$ext = explode(".", $file['name']);
$new_name = md5(uniqid());
$target_path = $location . $new_name .".".$ext[1];
if(move_uploaded_file($file['tmp_name'], $target_path))
{
$this->LibraryFiles->create();
$this->LibraryFiles->set('id', $new_name);
$this->LibraryFiles->set('library_id', $id);
$this->LibraryFiles->set('name', $file['name']);
$this->LibraryFiles->set('ext', $ext[1]);
$this->LibraryFiles->set('type', $file['type']);
$this->LibraryFiles->set('size', $file['size']);
if($this->LibraryFiles->save())
{
}
else
{
}
}
}
}
}