我一直试图在Elgg 3.x中保存一个Elgg 实体图标,但没有成功。myObject保存到数据库中,但是文件不会上传。
我做错了什么?
先谢谢大家。
save.php form
<?php
echo elgg_view('input/file', [
'name' => 'upload[]',
'multiple' => true,
'label' => 'picTuREs',
]);
?> save.php动作文件
foreach (elgg_get_uploaded_files('upload') as $upload)
{
$myObject = new ElggObject();
$myObject->subtype = "my_object";
$myObject->access_id = ACCESS_PUBLIC;
$myObject->saveIconFromUploadedFile($upload);
$myObject->save();
} 发布于 2022-05-26 17:33:18
更新您在以下方面的行动:
$upload_guids = (array) get_input('uploads');
if (empty($upload_guids)) {
return elgg_error_response(elgg_echo('file:error:empty_form'));
}
foreach ($upload_guids as $upload_guid) {
$file = new \ElggFile();
$file->title = $title;
$file->description = $description;
$file->access_id = $access_id;
$file->container_guid = $container_guid;
$file->tags = string_to_tag_array($tags);
$file->save();
if ($file->getSimpleType() === 'image') {
$file->saveIconFromElggFile($file);
}
} 如果使用自定义子类型,则应该通过这个对象扩展\ElggFile,如下所示:
class MyCustomFile extends \ElggFile {
const SUBTYPE = 'my_subtype';
protected function initializeAttributes() {
parent::initializeAttributes();
$this->attributes['subtype'] = self::SUBTYPE;
}
/**
* @see ElggEntity::saveIconFromElggFile()
*/
public function saveIconFromElggFile(\ElggFile $file, $type = 'icon', array $coords = array()) {
return false;
}
}https://stackoverflow.com/questions/61174541
复制相似问题