Пример #1
0
 private function getImageEditorInfo()
 {
     $path = $this->getPath();
     $file = isset($this->request->file) ? $this->request->file : '';
     $box = isset($this->request->box) ? (object) $this->request->box : '';
     $newname = !empty($this->request->newname) ? $this->makeSafe($this->request->newname) : '';
     if (!$path || !file_exists($path . $file)) {
         trigger_error('Image file is not specified', E_USER_WARNING);
     }
     $img = new abeautifulsite\SimpleImage();
     try {
         $img->load($path . $file);
     } catch (Exception $e) {
         trigger_error($e->getMessage(), E_USER_WARNING);
     }
     if ($newname) {
         $info = pathinfo($path . $file);
         $newname = $newname . '.' . $info['extension'];
         if (file_exists($path . $newname)) {
             trigger_error('File ' . $newname . ' already exists', E_USER_WARNING);
         }
     } else {
         $newname = $file;
     }
     if (file_exists($path . $this->config->thumbFolderName . DIRECTORY_SEPARATOR . $newname)) {
         unlink($path . $this->config->thumbFolderName . DIRECTORY_SEPARATOR . $newname);
     }
     $info = $img->get_original_info();
     return (object) array('path' => $path, 'file' => $file, 'box' => $box, 'newname' => $newname, 'img' => $img, 'width' => $info['width'], 'height' => $info['height']);
 }
Пример #2
0
//if (!file_exists('../../files')){
//	//если нет, то создаём\
//	mkdir('./../files'.uploads,777);
//}
//создаём уникальное имя для файла
$filename = md5(uniqid(rand(10000, 99999)));
$filename_copy = $filename . '_copy';
$file_dist = $_SERVER["DOCUMENT_ROOT"] . uploads . $filename . '.' . $ftype;
$file_copy_dist = $_SERVER["DOCUMENT_ROOT"] . uploads . $filename_copy . '.' . $ftype;
$tmpname = $file['tmp_name'];
if (!move_uploaded_file($tmpname, $file_dist)) {
    exit(createMessageJson(false, 'Ошибка при обработке файла изображения'));
}
//пока всё норм, далее конвертация
$img = new abeautifulsite\SimpleImage();
$img->load($file_dist)->resize(172, 126)->save($file_copy_dist);
unlink($file_dist);
//запись в базу
try {
    $database = new PDO('mysql:host=' . dbhost . ';dbname=' . dbname, dblogin, dbpassword);
    $qres = $database->prepare('insert into `projects` (`name`,`url`,`decsription`,`image`) values (:pname,:url,:description,:image)');
    $qres->bindValue(':pname', $name, PDO::PARAM_STR);
    $qres->bindValue(':url', $url, PDO::PARAM_STR);
    $qres->bindValue(':description', $description, PDO::PARAM_STR);
    $qres->bindValue(':image', $filename_copy . '.' . $ftype, PDO::PARAM_STR);
    $qres->execute();
    $database->NULL;
} catch (PDOException $e) {
    //ошибка,
    $res = "Ошибка!: " . $e->getMessage();
}