如果我不选择它,我的 file_url 字段总是在数据库中被删除。(即使图像已经集成)
如果在这种情况下单击“保存”,则会删除现场 PC 图像。
这是我的postImage()方法AdminCustomController
protected function postImage($id)
{
$file = isset($_FILES['file_url']) ? $_FILES['file_url'] : false;
if ($file && is_uploaded_file($file['tmp_name'])) {
$path = _PS_MODULE_DIR_ . 'custom/img/';
$tmp_arr = explode('.', $file['name']);
$filename = $file['name'];
if (!Tools::copy($file['tmp_name'], $path . $filename)) {
$errors[] = Tools::displayError('Failed to load image');
}
}
}
这是 renderForm()
public function renderForm()
{
$image_url = '';
if($this->object->file_url) {
$image_url = ImageManager::thumbnail(
_PS_MODULE_DIR_ . 'homecase/img/' . $this->object->file_url,
$this->table . $this->object->file_url,
150,
'jpg',
true,
true
);
}
$this->fields_form = [
//Entête
'legend' => [
'title' => $this->module->l('Edition'),
'icon' => 'icon-cog'
],
array(
'type' => 'file',
'label' => $this->l('PC Image'),
'name' => 'file_url',
'display_image' => true,
'image' => $image_url ? $image_url : false,
),
....
上传和保存在数据库中是好的。但是当图像存在并且我没有在该字段中选择其他图像时。该file_url字段在数据库中被删除。
你可以帮帮我吗?
谢谢 !
