Forums

Improving profile image edit

FenFire 19 Apr, 2015
Hi,
I have two more questions concerning handling of profile images (=avatar) in a self-made "Edit Profile" form:

1. I want the "delete_image" checkbox to be disabled if there isn't anything saved in Data.avatar. I tried:
window.onload = img;
function img() {
if (!jQuery("[name='Data[avatar]']").val()){document.getElementById('delete_image').disabled=true;}
}

It doesn't work...

2. If there is an old picture (Data.avatar) and picture (avatar) is renewed or "delete_image"-checkbox is clicked (activated), then the old profile picture should be deleted. I copied the path from the image upload FAQ but it doens't work (which means the picture is not deleted). This is a Load JS custom code before file upload action:
<?php
if  ($form->data['delete_image'] == 'yes') {
 $form->data['avatar'] = '';
  if ($form->data['Data']['avatar']) {
    unlink('JURI::root()."components/com_arrange2drive/media/users/{$form->data['Data']['avatar']}');
  }
}
if ($form->data['Data']['avatar'] && $form->data['avatar']) {
    unlink('JURI::root()."components/com_arrange2drive/media/users/{$form->data['Data']['avatar']}');
?>

What is wrong here?

Thanks in advance.
Christian
FenFire 19 Apr, 2015
I want to take back my first question; seems I did not refresh the page. It works.
The second one still is a problem.
GreyHead 19 Apr, 2015
Hi Christian,

The quotes in the unlink() lines don't look quite right. Please try
unlink( JURI::root()."components/com_arrange2drive/media/users/{$form->data['Data']['avatar']}" );
and
unlink( JURI::root()."components/com_arrange2drive/media/users/{$form->data['Data']['avatar']}" );

Bob
FenFire 20 Apr, 2015
Answer
Okay, the quotes weren't correct. I recognized that myself. But it still didn't work.

Now I came across the answer. I can't use JURI::root() - that's the URL address. I have to use $_SERVER['DOCUMENT_ROOT'] for the absolute server path. Now it works.
GreyHead 21 Apr, 2015
Hi Christian,

Sorry, I didn't spot that one. In Joomla! you can use JPATH_SITE for the server path so
unlink( JPATH_SITE.'/components/com_arrange2drive/media/users/'.$form->data['Data']['avatar'] );

Note that JURI::root() includes the following / while JPATH_SITE doesn't.

Bob
This topic is locked and no more replies can be posted.