Last active
April 7, 2016 13:51
-
-
Save mikhaildegtuarev/398f3f0367a0c6759be3ab3497cd7720 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$userId = $modx->user->id; | |
$user = $modx->getObject('modUser', $userId); | |
$profile = $user->getOne('Profile'); | |
$oldPhoto = $profile->get('photo'); | |
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['photo'])) { | |
$newimagePath = 'assets/uploads/profiles/' . $userId . '/'; // . $_FILES['photo']['name']; | |
if (!is_dir($newimagePath) ){ | |
mkdir($newimagePath); | |
} | |
$newimagePath .=$_FILES['photo']['name']; | |
if (copy($_FILES['photo']['tmp_name'], $hook->modx->config['base_path'] . $newimagePath)) { | |
unlink($hook->modx->config['base_path'] . $oldPhoto); | |
$profile->set('photo', $newimagePath); | |
$profile->save(); | |
$modx->setPlaceholder('photo', $profile->get('photo')); | |
} | |
} else { | |
$modx->setPlaceholder('photo', $profile->get('photo')); | |
} | |
/* ВЫВОД */ | |
[[!changePhoto]] | |
<form action="[[~[[*id]]]]" method="POST" id="info_form" enctype="multipart/form-data" > | |
<div class="lich-kabinet-right"> | |
<div class="lich-kabinet-right-left"> | |
<!-- FARMER --> | |
<div id="farmer" class="kontent-center"> | |
<div class="images kontent-center"> | |
<img class="avatar" src="[[+photo]]" alt=""> | |
<div class="photo_user"> | |
<input type="file" name="photo" value="[[!+photo]]" /><input type="button" value="Выбрать фото" class="button-btn"> | |
</div> | |
<input type="button" onclick="$('#info_form').submit();" name="save" value="Сохранить" class="button-btn"> | |
</div> | |
</div> | |
</div> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment