Hi everyone! I'm using
Avatar 1.0.0-pl
When I try to upload an avatar, I get error:
Warning: mkdir() [function.mkdir]: No such file or directory in /var/www/yan/data/www/mmonstr.ru/core/cache/includes/elements/modsnippet/21.include.cache.php on line 115
I think the reason is that there is no such a folder on the server, where the script wants to upload an image. But I can't understand, where this folder must be located and how it must be named. I looked at the script's source code, but did't find that path.
Here's the source code of the snippets:
1. avatar.upload:
<?php
/**
Avatar
Copyright 2011 by Yuri Kobets <[email protected]>
Avatar is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) any
later version.
Avatar is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@package avatar
*/
/**
MODx avatar.upload Snippet
With this snippet your users can upload avatars for the profile
@package avatar
@property textfield defavatar: the url to the default avatar.
@property textfield maxwidth: the maximum width of the avatar.
@property textfield maxheight: the maximum height of the avatar.
Snippet sets the placeholders:
uploadavatar.update_error: 1 if there is an error 0 if successfully updated
uploadavatar.error: error text
uploadavatar.avatarurl: url to the avatar. You can use this url in the img src
*/
if(!$modx->user->isAuthenticated())
{
return '';
}
$defavatar = $modx->getOption('defavatar', $scriptProperties, '/assets/images/avatars/default.png');
$maxwidth = $modx->getOption('maxwidth', $scriptProperties, 100);
$maxheight = $modx->getOption('maxheight', $scriptProperties, 100);
$userspath = $modx->getOption('avatar_users_path');
$usersurl = $modx->getOption('avatar_users_url');
$searchArray = array(
'{core_path}',
'{assets_path}',
'{base_path}',
);
$replacePaths = array(
$modx->getOption('core_path',null,MODX_CORE_PATH),
$modx->getOption('assets_path',null,MODX_ASSETS_PATH),
$modx->getOption('base_path',null,MODX_BASE_PATH),
);
$userspath = str_replace($searchArray, $replacePaths, $userspath);
$modx->lexicon->load('avatar:default');
$profile = $modx->user->getOne('Profile');
if(empty($profile))
{
return '';
}
$params = $modx->request->getParameters(array(), 'POST');
$modx->setPlaceholder("uploadavatar.update_error", 0);
if(!empty($params['upload-btn']))
{
if($_FILES['uploadfile']['size'] != 0)
{
$iserror = 0;
$avatarfile = '';
$fileInfo = pathinfo(basename($_FILES['uploadfile']['name']));
if(strtolower($fileInfo["extension"]) != "png" &&
strtolower($fileInfo["extension"]) != "jpg" &&
strtolower($fileInfo["extension"]) != "gif" &&
strtolower($fileInfo["extension"]) != "jpeg")
{
$modx->toPlaceholder('uploadavatar.error', $modx->lexicon('avatar.notimage'));
$iserror = 1;
} else
{
$imgSize = getimagesize($_FILES['uploadfile']['tmp_name']);
if(is_array($imgSize))
{
if($imgSize[0] > $maxwidth || $imgSize[1] > $maxheight)
{
$errmsg = sprintf($modx->lexicon('avatar.errdim'), $maxwidth . 'x' . $maxheight);
$modx->setPlaceholder("uploadavatar.error", $errmsg);
$iserror = 1;
}
} else
{
$modx->setPlaceholder("uploadavatar.error", $modx->lexicon('avatar.notimage'));
$iserror = 1;
}
if(!$iserror)
{
$saveto = $userspath . '/' . $modx->user->get('id');
if(!file_exists($saveto))
{
if(!mkdir($saveto))
{
$modx->setPlaceholder("uploadavatar.error", $modx->lexicon('avatar.errinternal'));
$iserror = 1;
}
}
if(!$iserror)
{
$oldphoto = $profile->get('photo');
$avatarfile = 'avatar.' . $fileInfo["extension"];
$oldphotopath = $saveto . '/' . $oldphoto;
$saveto = $saveto . '/' . $avatarfile;
if(file_exists($_FILES['uploadfile']['tmp_name']))
{
if(!move_uploaded_file($_FILES['uploadfile']['tmp_name'], $saveto))
{
$modx->setPlaceholder("uploadavatar.error", $modx->lexicon('avatar.errinternal'));
$iserror = 1;
} else if(!empty($oldphoto) && $oldphoto != $avatarfile)
{
if(file_exists($oldphotopath))
{
unlink($oldphotopath);
}
}
} else
{
$modx->setPlaceholder("uploadavatar.error", $modx->lexicon('avatar.errinternal'));
$iserror = 1;
}
}
}
}
if(!$iserror)
{
$avatarurl = $avatarfile;
$profile->set('photo', $avatarurl);
$profile->save();
$modx->setPlaceholder("uploadavatar.update_error", 0);
} else
{
$modx->setPlaceholder("uploadavatar.update_error", 1);
}
} else
{
if(!empty($params['delete']))
{
$saveto = $userspath . '/' . $modx->user->get('id') . '/' . $profile->get('photo');
if(file_exists($saveto))
{
unlink($saveto);
}
$profile->set('photo', '');
$profile->save();
}
}
}
$photo = $profile->get('photo');
if(!empty($photo))
{
$configs = $modx->getConfig();
$avatarurl = $configs['site_url'] . $usersurl . '/' . $modx->user->get('id') . '/' . $photo;
$modx->setPlaceholder('uploadavatar.avatarurl', $avatarurl);
} else
{
$modx->setPlaceholder('uploadavatar.avatarurl', $defavatar);
}
2. avatar.url:
<?php
/**
Avatar
Copyright 2011 by Yuri Kobets <[email protected]>
Avatar is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) any
later version.
Avatar is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@package avatar
*/
/**
MODx avatar.url Snippet
This the Output Filter can be used to show the user avatar
Usage:
<img src="[[+createdby:avatar.url=`assets/images/defavatar.png`]]">
input string is the default avatar url.
*/
$user = $modx->getObject('modUser', array('id' => $input));
if(empty($user))
{
return $options;
}
$profile = $user->getOne('Profile');
if(empty($profile))
{
return $options;
}
$photo = $profile->get('photo');
if(!empty($photo))
{
$configs = $modx->getConfig();
$usersurl = $modx->getOption('avatar_users_url');
return $configs['site_url'] . $usersurl . '/' . $modx->user->get('id') . '/' . $photo;
} else
{
return $options;
}
[ed. note: webstyle last edited this post 13 years, 7 months ago.]