function addAllImages() { if (!empty($this->mainImage)) { $mImage = str_replace('//', '/', $this->path . 'main_' . Generator::strToLat($this->mainImage)); $this->addImage($mImage, TRUE); Helper::moveFile('mainimage', TRUE, $this->productId); } if (!empty($this->images[0]) && is_array($this->images)) { foreach ($this->images as $img) { $image = str_replace('//', '/', $this->path . Generator::strToLat($img)); $this->addImage($image, FALSE); } Helper::moveFile('images', FALSE, $this->productId); } }
public function updateAvatar() { if (empty($this->id)) { $this->id = $this->user['id']; } $this->path = $this->path . $this->id; try { if ($this->photo) { $st = $this->db->prepare("UPDATE {$this->table} SET `photo` = ? WHERE `id` = ?"); $st->execute([$this->path . '/avatar/' . Generator::strToLat($this->photo), intval($this->id)]); } } catch (Exception $ex) { $ex->getMessage(); } }
public static function moveFile($inputName, $isMain, $id = NULL, $fileType = 'img') { if (!$id) { $id = date('d_m_Y'); } if ($fileType === 'img' || $fileType === 'image') { $path = Path::IMG_UPLOAD_DIR . $id; } elseif ($fileType === 'userimg') { $path = Path::USERIMG_UPLOAD_DIR . $id; } elseif ($fileType === 'slide') { $path = Path::IMG_UPLOAD_DIR_SLIDER . $id; } else { $path = Path::FILE_UPLOAD_DIR . $id; } if (!is_dir($path)) { if (!mkdir($path, 0777, TRUE)) { die('Не удалось создать директорию ' . $path); } } $prefix = $isMain ? 'main_' : ''; if (!empty($_FILES[$inputName]['name'])) { //for multiple if (is_array($_FILES[$inputName]['name'])) { foreach ($_FILES[$inputName]['name'] as $idx => $name) { $uploadFile = $path . '/' . $prefix . Generator::strToLat($name); copy($_FILES[$inputName]['tmp_name'][$idx], $uploadFile); } } else { //for one file $fileName = Generator::strToLat($_FILES[$inputName]['name']); $uploadFile = $path . '/' . $prefix . $fileName; copy($_FILES[$inputName]['tmp_name'], $uploadFile); } } else { return FALSE; } }
public function updatePhoto() { if (empty($this->id)) { $this->id = $this->user['id']; } $this->path = $this->path . $this->id; try { if ($this->photo) { $st = $this->db->prepare("UPDATE {$this->table} SET `photo` = :photo WHERE `id` = :id"); $st->execute([':photo' => $this->path . '/main_' . Generator::strToLat($this->photo), ':id' => $this->id]); Helper::moveFile('photo', TRUE, $this->id, 'userimg'); } } catch (Exception $ex) { $ex->getMessage(); } }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = new stdClass(); $file->name = Generator::strToLat($this->get_file_name($name, $type, $index, $content_range)); $file->size = $this->fix_integer_overflow(intval($size)); $file->type = $type; if ($this->validate($uploaded_file, $file, $error, $index)) { $this->handle_form_data($file, $index); $upload_dir = $this->get_upload_path(); if (!is_dir($upload_dir)) { mkdir($upload_dir, $this->options['mkdir_mode'], true); } $file_path = $this->get_upload_path($file->name); $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND); } else { move_uploaded_file($uploaded_file, $file_path); } } else { // Non-multipart uploads (PUT method support) file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0); } $file_size = $this->get_file_size($file_path, $append_file); if ($file_size === $file->size) { $file->url = $this->get_download_url($file->name); list($img_width, $img_height) = @getimagesize($file_path); if (is_int($img_width)) { $this->handle_image_file($file_path, $file); } } else { $file->size = $file_size; if (!$content_range && $this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'abort'; } } $this->set_file_delete_properties($file); } return $file; }
echo $popularProducts; ?> </div><!--features_items--> <div class="category-tab"><!--category-tab--> <div class="col-sm-12"> <ul class="nav nav-tabs"> <? if (!empty($currentCategory) && is_array($currentCategory)): ?> <li class="subCatTitle pull-right"><i class="fa fa-arrow-left"></i> <?php echo $currentCategory[0]['category_name']; ?> </li> <? foreach ($currentCategory as $k => $c): ?> <? $active = ($k === 0) ? 'active' : '' ?> <? $subToLat = Generator::strToLat($c['subcategory_name']) ?> <? $sub = Helper::strSplitter($c['subcategory_name']) ?> <li class="<?php echo $active; ?> "><a href="#<?php echo $subToLat; ?> " class="showSubsProducts" data-toggle="tab" data-id="<?php echo $c['id']; ?> "><?php echo $sub; ?> </a></li> <? endforeach; ?>