Fix delete of image

This commit is contained in:
Laurent Destailleur 2015-12-21 17:32:20 +01:00
parent db7a98f0ef
commit dcbad8bb15
2 changed files with 17 additions and 19 deletions

View File

@ -288,17 +288,16 @@ if (empty($reshook))
// Photo save
$dir = $conf->societe->dir_output."/contact/".$object->id."/photos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if (GETPOST('deletephoto') && $object->photo)
{
$fileimg=$dir.'/'.$object->photo;
$dirthumbs=$dir.'/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
$object->photo = '';
}
if ($file_OK)
{
if (GETPOST('deletephoto'))
{
$fileimg=$dir.'/'.$object->photo;
$dirthumbs=$dir.'/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
$object->photo = '';
}
if (image_format_supported($_FILES['photo']['name']) > 0)
{
dol_mkdir($dir);
@ -980,7 +979,7 @@ else
print "<br>\n";
}
print '<table class="nobordernopadding">';
if ($object->photo) print '<tr><td><input type="checkbox" class="flat" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
if ($object->photo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
//print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
print '</table>';

View File

@ -567,16 +567,15 @@ if (empty($reshook))
// Logo/Photo save
$dir = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if (GETPOST('deletephoto') && $object->photo)
{
$fileimg=$dir.'/'.$object->logo;
$dirthumbs=$dir.'/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
}
if ($file_OK)
{
if (GETPOST('deletephoto'))
{
$fileimg=$dir.'/'.$object->logo;
$dirthumbs=$dir.'/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
}
if (image_format_supported($_FILES['photo']['name']) > 0)
{
dol_mkdir($dir);
@ -1837,7 +1836,7 @@ else
{
if ($object->logo) print "<br>\n";
print '<table class="nobordernopadding">';
if ($object->logo) print '<tr><td><input type="checkbox" class="flat" name="deletephoto photodelete" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
if ($object->logo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
//print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
print '</table>';