private static function process() { if (isset($_FILES['uploadFile'])) { $newfile = 'media/files/' . time() . '-' . $_FILES['uploadFile']['name']; $file = File::uploadFile($_FILES['uploadFile'], $newfile, false); if ($file !== false && !is_array($file)) { Router::redirect("/setExport?file=" . $_FILES['uploadFile']['name']); } } // foreach (self::$files as $filename) // self::convertFile($filename); }
function update(Volunteer $obj) { $dir = realpath(root . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "volunteers"); $file = new File($dir); $columns = array('name', 'fb', 'tw', 'gp', 'email', 'about'); $data = array($_REQUEST['name'], $_REQUEST['fb'], $_REQUEST['tw'], $_REQUEST['gp'], $_REQUEST['email'], $_REQUEST['about']); if (isset($_FILES['image']['name']) && !empty($_FILES['image']['name'])) { $unique_name = uniqid() . "." . pathinfo(basename($_FILES['image']['name']), PATHINFO_EXTENSION); $images = $unique_name; $file->uploadFile($unique_name, $_FILES['image']['tmp_name']); $columns[] = 'image'; $data[] = $unique_name; } return $obj->updateVolunteerInfo($_REQUEST['id'], $columns, $data); }
function update(Clients $obj) { $dir = realpath(root . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "clients"); $file = new File($dir); $columns = array('name', 'about'); $data = array($_REQUEST['name'], $_REQUEST['about']); if (isset($_FILES['logo']['name']) && !empty($_FILES['logo']['name'])) { $unique_name = uniqid() . "." . pathinfo(basename($_FILES['logo']['name']), PATHINFO_EXTENSION); $images = $unique_name; $file->uploadFile($unique_name, $_FILES['logo']['tmp_name']); $columns[] = 'logo'; $data[] = $unique_name; } return $obj->updateClient($_REQUEST['id'], $columns, $data); }
<?php // echo "<pre>"; // print_r($_FILES["file"]); // //echo this; // echo "</pre>"; // echo "<pre>"; // print_r($_REQUEST); // //echo this; // echo "</pre>"; // exit; $result = File::uploadFile($_REQUEST, $_FILES); if ($result > 0) { // echo "<pre>"; // print_r($result); // //echo this; // echo "</pre>"; // // exit; echo "Your upload was successful!"; } else { if ($result == -6) { echo "The thumbnail wasn't created and the upload was currupted. Please try again!"; } else { if ($result == -5) { echo "The upload already exists. Please rename the file and try again!"; } else { if ($result == -4) { echo "The file wasn't saved correctly. Please try again."; } else { if ($result == -3) { echo "There was an error saving the upload. Please try again!";
$id = $_REQUEST['id']; if ($ne->updateEvent($id, $_REQUEST['name'], $_REQUEST['time'], $_REQUEST['venue'], $_REQUEST['desc'])) { Message::setSuccessMessage("Event updated successfully"); header("location:" . $config->site_address . "news-event-admin/"); } else { Message::setFailMessage("Something went wrong please try again."); header("location:" . $config->site_address . "news-event-admin/edit/" . $id); } } else { if ($_REQUEST['action'] == 'edit_n') { $id = $_REQUEST['id']; $file = $ne->getNEInfo($id, 'cover'); if (!Validation::isNull($_FILES['cover']['name'])) { $fileobj->deleteFile($file); $file = uniqid() . "." . pathinfo(basename($_FILES['cover']['name']), PATHINFO_EXTENSION); $fileobj->uploadFile($file, $_FILES['cover']['tmp_name']); } if ($ne->updateNews($id, $_REQUEST['name'], $file, $_REQUEST['desc'])) { Message::setSuccessMessage("News updated successfully"); header("location:" . $config->site_address . "news-event-admin/"); } else { Message::setFailMessage("Something went wrong please try again."); header("location:" . $config->site_address . "news-event-admin/edit/" . $id); } } else { if ($_REQUEST['action'] == 'del_ne') { if ($ne->deleteNE($_REQUEST['id'])) { Message::setSuccessMessage("News/Event deleted successfully. Files related to news/event can not be deleted. you can delete them manually from 'static/news/' or 'static/img' folder."); } else { Message::setFailMessage("Something went wrong please try again."); }
<?php require_once __DIR__ . "/../autoload/session.autoload.php"; require_once __DIR__ . "/../class/Document.class.php"; require_once __DIR__ . "/../class/File.class.php"; require_once __DIR__ . "/../class/Time.class.php"; if (isset($_POST)) { $Document = new Document(); $File = new File(); if (is_uploaded_file($_FILES['file']['tmp_name'])) { $File->setFile($_FILES['file']); $replyFile = $File->uploadFile(); if (!$replyFile) { header("location:/error.php"); } else { $Document->setDate(Time::getFrenchDate()); $Document->setFileLink($File->getFileLink()); $Document->setAuthor($_SESSION['username']); $Document->addDoc(); header("location:/documents.php?event=added"); } } else { header("location:/documents.php?event=error"); } }
private function uploadFile($nombre) { $upload = new File(); return $upload->uploadFile($nombre); }
<?php include '../core/includes.php'; $dir = realpath(root . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "gallery"); $config = new Config(); $auth = new Auth(); $file = new File($dir); if (!$auth->isAdmin()) { header("Location:" . $config->site_address . "login"); } $action = ""; if (isset($_REQUEST['action'])) { $action = $_REQUEST['action']; } if ($action == 'add') { if (isset($_FILES['photo']['name'][0]) && !empty($_FILES['photo']['name'][0]) && $_FILES['photo']['name'][0] != "") { $images = array(); $i = 0; foreach ($_FILES['photo']['name'] as $image) { $unique_name = uniqid() . "." . pathinfo(basename($image), PATHINFO_EXTENSION); $images[] = $unique_name; $file->uploadFile($unique_name, $_FILES['photo']['tmp_name'][$i]); $i++; } } } else { if ($action == 'remove') { $file->deleteFile($_REQUEST['path']); } } header("Location:" . $_REQUEST['return_path']);
public function saveEvaluacion() { $objeto["id"] = 0; $objeto["postulacion_id"] = $postulacion_id = $_POST["postulacion_id"]; $objeto["valor"] = $valor = $_POST["valor"]; $objeto["observacion"] = $_POST["observaciones"]; $objeto["aprobado"] = $aprobado = 0; if ($valor >= 8) { $objeto["aprobado"] = $aprobado = 1; } //$objeto["aprobado"] = $aprobado = $_POST["aprobado"]; $objeto["activo"] = 1; $objeto["fecha"] = date('Y-m-d'); $objeto["id_usuario"] = $_SESSION['SESSION_USER']['id']; $objeto["etapa_id"] = $etapa_id = $_POST["etapa_id"]; if ($etapa_id == 5) { $objeto["aprobado"] = $aprobado = $_POST["aprobado"]; $objeto["observacion"] = "Designado Ganador!"; if ($aprobado != 1) { $objeto["observacion"] = "Designado No Ganador!"; } } $objeto['url'] = ''; if (isset($_FILES['url']) && $_FILES['url']['name'] != '') { $upload = new File(); $objeto['url'] = $upload->uploadFile('evaluacion' . $objeto["etapa_id"] . "_"); } try { $model = new PostulacionModel(); $objeto = $model->saveEvaluacion($objeto); $user = $model->getPostulanteByPostulancion($postulacion_id); $name = $user["nombres"] . " " . $user["apellidos"]; $vacante = $model->getVacanteByPostulancion($postulacion_id); $etapa = $model->getEtapaById($etapa_id); $email = new Email(); $email->sendNotificacionPostulacion($name, $vacante["nombre_vacante"], $user["email"], $etapa[0]["nombre"], $valor, $aprobado); $_SESSION['message'] = "Datos almacenados correctamente."; } catch (Exception $e) { $_SESSION['message'] = $e->getMessage(); } header("Location: index.php?action=loadPostulante"); }
public function run($args) { $max_id = isset($args[0]) ? $args[0] : 0; $root = dirname(dirname(__DIR__)); $parceBase = 'tiu_last'; $log_spec = '/tmp/importTiuSpec.log'; $log = '/tmp/importTiu.log'; $k = file_get_contents($root . $log); $uploadDirectory = Yii::getPathOfAlias('webroot') . '/uploads/'; $db = \Yii::app()->db; Yii::app()->setImport(['application.modules.store.models.*', 'application.models.*']); if ($max_id == 0) { $max_id = $db->createCommand()->select('MAX(id)')->from($parceBase . '.product')->queryScalar(); } // импорт категорий if ($k == 0) { // перед созданием категорий все чистим echo "Clear tables and files... \n"; $this->clear($uploadDirectory); echo "Set defaults... \n"; $this->setDefault(); $db->setActive(true); Yii::app()->language = 'ru'; $categories = $db->createCommand("\n SELECT name, id_item, id_parent FROM " . $parceBase . ".category_all\n ")->queryAll(); echo "Import categories... \n"; foreach ($categories as $dump_category) { $category = new StoreCategory(); $category->name_ru = $dump_category['name']; $category->tiu_id_item = $dump_category['id_item']; $category->status = 1; $name_translit = \yupe\helpers\YText::translit(str_replace(" ", "-", $dump_category['name'])); $slug = $db->createCommand()->select('slug')->from('site_store_category')->where('slug = "' . $name_translit . '"')->queryScalar(); if ($slug === FALSE) { $category->slug = $name_translit; } else { //$category->slug = time() . '_' . $name_translit; $category->slug = substr(md5($category->tiu_id_item), 0, 10) . '_' . $name_translit; //echo $category->slug."\n"; } $parent_id = $db->createCommand()->select('id')->from('site_store_category')->where('tiu_id_item = "' . $dump_category['id_parent'] . '"')->queryScalar(); $category->parent_id = $parent_id ? $parent_id : 1; if (!$category->save()) { echo "\n"; echo "Error save StoreCategory for tiu_id_item = " . $category->tiu_id_item . "\n"; echo "\n"; } } // создание типов echo "Create types... \n"; $db->setActive(true); $cats = $db->createCommand("SELECT * FROM site_store_category")->queryAll(); foreach ($cats as $cat) { $Type = new Type(); $Type->name = $cat['slug']; if (!$Type->save()) { echo "\n"; echo "Error save Type for {$cat['slug']} \n"; echo "\n"; continue; } // добавим постоянные характеристики foreach ($this->attr_id as $attr_id) { $TypeAttribute = new TypeAttribute(); $TypeAttribute->type_id = $Type->id; $TypeAttribute->attribute_id = $attr_id; $TypeAttribute->save(); } } $k = 1; file_put_contents($root . $log, $k); } // импорт продуктов echo "Import products... \n"; echo "Max ID {$max_id} \n"; for ($k; $k <= $max_id; $k++) { // $db->setActive(false); $db->setActive(true); $dump_product = $db->createCommand()->select('*')->from($parceBase . '.product')->where('id =' . $k)->queryRow(); if ($dump_product) { $name_translit = \yupe\helpers\YText::translit(str_replace(" ", "", $dump_product['name'])); if (empty($name_translit)) { file_put_contents($root . $log, $dump_product['id']); continue; // нет имени } $id_cat = $db->createCommand()->select('id_cat')->from($parceBase . '.productToCat')->where('id_product =' . $dump_product['id'])->queryScalar(); if ($id_cat === FALSE) { file_put_contents($root . $log, $dump_product['id']); continue; // нет категории } // скачаем файлы $image = $db->createCommand()->select('url')->from($parceBase . '.image')->where('id_item =' . $dump_product['id'])->queryRow(); if ($image !== null && $image['url'] != '') { $imageContent = $this->getData($image['url']); if ($imageContent) { $this->addToFiles('qqurl', $image['url']); $file = new File(); $fileinfo = $file->uploadFile($uploadDirectory, array("jpg", "png", "jpeg"), 'Product'); // создание продукта $sl = $db->createCommand()->select('slug')->from('site_store_product')->where('slug = "' . $name_translit . '"')->queryScalar(); if ($sl === FALSE) { $slug = $name_translit; } else { //$slug = time() . '_' . $name_translit; $slug = substr(md5($dump_product['id']), 0, 10) . '_' . $name_translit; } $category = $db->createCommand()->select('id, slug')->from('site_store_category')->where('tiu_id_item = "' . $id_cat . '"')->queryRow(); if ($category) { $category_id = $category['id']; $type_id = $db->createCommand()->select('id')->from('site_store_type')->where("name = '{$category['slug']}'")->queryScalar(); if ($type_id === FALSE) { print_r(" Error: can`t find StoreType for category_id = {$category_id} \n"); file_put_contents($root . $log, $dump_product['id']); continue; } $sql = "INSERT INTO `site_store_product` (`name`, `description`, `price`, `user_id`, `slug`, `category_id`, `type_id`, `tiu_id`) VALUES ('" . $dump_product["name"] . "',:description,'" . $dump_product["price"] . "',1,'" . $slug . "'," . $category_id . "," . $type_id . "," . $dump_product['id'] . ")"; } else { $sql = "INSERT INTO `site_store_product` (`name`, `description`, `price`, `user_id`, `slug`, `category_id`, `type_id`, `tiu_id`) VALUES ('" . $dump_product["name"] . "',:description,'" . $dump_product["price"] . "',1,'" . $slug . "',NULL,NULL," . $dump_product['id'] . ")"; $category_id = NULL; $type_id = NULL; } $command = $db->createCommand($sql); $command->bindParam(':description', $dump_product["description"], PDO::PARAM_STR); $sql = $db->quoteValue($sql); $command->execute(); $product_id = $db->getLastInsertID(); // id в c2go // обработаем характеристики текущего продукта $specs = $db->createCommand()->select('id_product, name, value')->from($parceBase . '.specification')->where('id_product =' . $dump_product['id'])->queryAll(); foreach ($specs as $spec) { if (!empty($spec['name']) and !empty($spec['value'])) { $name = \yupe\helpers\YText::translit($spec['name']); if (in_array($name, $this->attr_name)) { // пропускаем постоянные continue; } $sql = "INSERT INTO `site_store_product_option` (`product_id`, `title`, `value`) \n VALUES ('" . $product_id . "',:name,:value)"; $command = $db->createCommand($sql); $command->bindParam(':name', $spec["name"], PDO::PARAM_STR); $command->bindParam(':value', $spec["value"], PDO::PARAM_STR); $sql = $db->quoteValue($sql); $command->execute(); } //$this->saveSpec($spec, $product_id, $category_id, $type_id); } file_put_contents($root . $log_spec, $dump_product['id']); // связь продукта и файла if (array_key_exists('id', $fileinfo)) { $model = File::model()->findByPk($fileinfo['id']); if ($model) { $model->record_id = $product_id; $model->update(); } } print_r($dump_product['id'] . ' ' . $slug . "\n"); } } file_put_contents($root . $log, $dump_product['id']); } } \Yii::app()->mail->send('*****@*****.**', '*****@*****.**', 'Импорт', 'Импорт категорий, товаров и характеристик завершен'); //file_put_contents($root . $log, 0); }