Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- UserSpice 4
- An Open Source PHP User Management System
- by the UserSpice Team at http://UserSpice.com
- This program 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 3 of the License, or
- (at your option) any later version.
- This program 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.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- require_once '../init.php';
- require_once '../classes/class.upload.php';
- $db = DB::getInstance();
- $userID = $user->data()->id;
- $profileQ = $db->query("SELECT * FROM profiles WHERE user_id = ?",array($userID));
- $thisProfile = $profileQ->first();
- $id = $thisProfile->id;
- $path_type = Input::get('path');
- $dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : $path_type);
- if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'image') {
- // ---------- IMAGE UPLOAD ---------- //
- //:: we create an instance of the class, giving as argument the PHP object
- //:: corresponding to the file field from the form
- //:: All the uploads are accessible from the PHP object $_FILES
- $handle = new Upload($_FILES['avatars']);
- //:: then we check if the file has been uploaded properly
- //:: in its *temporary* location in the server (often, it is /tmp)
- if ($handle->uploaded) {
- //:::::::::::::::::::::::::: see here for more options :::::::::::::::::::::::::::::::::::::::::://
- //:::: https://github.com/verot/class.upload.php ::::://
- //:::: :::://
- //:::: yes, the file is on the server ::://
- //:::: below are some example settings which can be used if the uploaded file is an image. ://
- //::::::::::::::::::::::::::::: Uncomment to use ::::::::::::::::::::::::::::::::::::::::::://
- //::::::::::::::: determines is an image will be resized :::::::::::::::::::::::::://
- $handle->image_resize = true;
- //::::::::::::::: destination image width (default: 150) :::::::::::::::::::::::::://
- //:::::::::::::::: used only if image_resize == true ::::::::::::::::::::::::::://
- $handle->image_x = 230;
- //::::::::::::::: destination image height (default: 150) ::::::::::::::::::::::::://
- //:::::::::::::::: used only if image_resize == true ::::::::::::::::::::::::::://
- $handle->image_y = 230;
- //:::::::::::::::::::::::; image will be converted :;;:::::::::::::::::::::::::://
- //:::::: (possible values : ''|'png'|'jpeg'|'gif'|'bmp'; default: '') :::::::::://
- //$handle->image_convert = 'jpg';
- //:::::::::::::::: text label on the image, value is a string :::::::::::::::::::://
- //$handle->image_text = 'test';
- //:::::::::::::::: text label on the image, value is a string :::::::::::::::::::://
- //:::::::::: watermark on the image, value is a local filename. :::::::::::::::::://
- //:::::::::: accepted files are GIF, JPG, BMP, PNG and PNG alpha :::::::::::::::://
- //$handle->image_watermark = 'watermark.png';
- //:::::::::::::::: watermark position withing the image :::::::::::::::::::://
- //::::: combination of one or two from 'TBLR': top, bottom, left, right :::://
- //$handle->image_watermark_position = 'LR';
- //:::::::::::::::: Format is either in pixels or percentage :::::::::::::::::::://
- //:::::::::::::::::::::: such as 40, '40', '40px' or '40%' ::::::::::::::::::::://
- //$handle->image_reflection_height = '25%';
- //:::::::::::::::: in pixels between the source image and the reflection :::::://
- //::::::::::::::::::::::::::::::: can be negative ::::::::::::::::::::::::::::://
- //$handle->image_reflection_space = 3;
- //:::::::::::::::: opacity level at which the reflection starts :::::://
- //:::::::::::::::::::::::: integer between 0 and 100 :::::::::::::::://
- //$handle->image_reflection_opacity = 60;
- //::::::::::::: Compression level for PNG images ::::::::::::::::::::::::::::::::::::://
- //:::::::::::: between 1 (fast but large files) and 9 (slow but smaller files) :::::://
- //$handle->png_compression = 9;
- //::::::::::::: Compression quality for JPEG images (default: 85) :::::::::::::::::://
- $handle->jpeg_quality = 99;
- //::::::::::::: if set to a size in bytes, ::::::::::::::::::::::::::::::::::::::::::://
- //::::: will approximate jpeg_quality so the output image fits within the size :::::://
- $handle->jpeg_size = 1072;
- //::::: 1024 = 1KB, 51200 = 50kb :::::::::::::::::::::::::::::::::::::::::::::::::::::://
- //$handle->file_max_size = '51200';
- //::::: Allowed mime types || 'application/pdf','application/msword', 'image/*' :::::://
- //::::::::::::::::::::::: wildcard accepted, as in image/* ::::::::::::::::::::::::://
- $handle->allowed = array('image/jpg', 'image/png');
- //::::: Forbidden mime types || 'application/pdf','application/msword', 'image/*' :::::://
- //::::::::::::::::::::::: wildcard accepted, as in image/* ::::::::::::::::::::::::::://
- $handle->forbidden = array('application/*');
- //::::: now, we start the upload 'process'. That is, to copy the uploaded file ::::://
- //::::: from its temporary location to the wanted location ::::::::::::::::::::::://
- //::::: It could be something like $handle->Process('/home/www/my_uploads/'); :::://
- $handle->Process('../uploads/'. $path_type);
- //:: we check if everything went OK
- if ($handle->processed) {
- //:: everything was fine !
- $old_photo = Input::get('old_photo');
- $path_type = Input::get('path');
- $id = Input::get('id');
- if($old_photo !='smile.png'){
- unlink($path_type.'/'. $old_photo);
- }
- //::::::::::: Store the file name & extension to db :::::::::://
- $db->update('profiles',$id,['avatar'=>$handle->file_dst_name]);
- //:::::::::: Store complete path + filename & extension to db :::::://
- //$db->update('profiles',$id,['avatar'=>$handle->file_dst_pathname]);
- //:::::::::: On Success Redirect to existing page / or another if prefered :::::://
- Redirect::to('../edit_profile.php');
- } else {
- //:: one error occured
- echo '<p class="result">';
- echo ' <b>File not uploaded to the wanted location</b><br />';
- echo ' Error: ' . $handle->error . '';
- echo '</p>';
- }
- //:: we delete the temporary files
- $handle-> Clean();
- } else {
- //:: if we're here, the upload file failed for some reasons
- //:: i.e. the server didn't receive the file
- echo '<p class="result">';
- echo ' <b>File not uploaded on the server</b><br />';
- echo ' Error: ' . $handle->error . '';
- echo '</p>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement