/** * @param $fileUrl * * @return string * @throws \PHPImageWorkshop\Core\Exception\ImageWorkshopLayerException * @throws \PHPImageWorkshop\Exception\ImageWorkshopException */ private function resize($fileUrl) { if (!$this->allowedDimensions) { include projectRoot . '/conf/allowedImageSizes.conf'; } $modificator = ''; $returnTo = ''; $file = explode('/', $fileUrl); $fileName = array_pop($file); array_pop($file); $size = array_pop($file); $file = implode('/', $file); $folder = rtrim(documentRoot, '/') . BM_C_IMAGE_FOLDER . $file . '/' . $size . '/' . mb_substr($fileName, 0, 2) . '/'; @mkdir($folder, 0777, true); bmTools::chmodPath(BM_C_IMAGE_FOLDER . $file . '/' . $size . '/' . mb_substr($fileName, 0, 2), 0777); $originFile = rtrim(documentRoot, '/') . BM_C_IMAGE_FOLDER . $file . '/originals/' . mb_substr($fileName, 0, 2) . '/' . $fileName; $url = BM_C_IMAGE_FOLDER . $file . '/' . $size . '/' . mb_substr($fileName, 0, 2) . '/' . $fileName; if (in_array($size, $this->allowedDimensions) && file_exists($originFile)) { $geometry = $this->getGeometry($originFile, $size); if ($geometry != 'copy') { imagemagick_convert(' -resize ' . $geometry . ' ' . $originFile . ' ' . $folder . $fileName); } else { copy($originFile, $folder . $fileName); } exec('chmod 0777 ' . $folder . $fileName); $returnTo = $url; } return $returnTo; }
public function query($sqltext) { //echo($sqltext ."\n--------------------\n"); if ($this->mysqli && $sqltext != '') { //file_put_contents(documentRoot . '/sql.txt' ,$_SERVER["REQUEST_URI"] . "\n" . '=============================================<br />' . $sqltext . '<br />==============================' . "\n", FILE_APPEND); $timeStart = microtime(true); $result = $this->mysqli->query($sqltext, $this->linkId); if (defined('C_BM_DEBUG') && C_BM_DEBUG === true && $this->application->bmDebug) { $this->application->bmDebug->query($sqltext); $this->application->bmDebug->stopTimer(); } ++$this->queriesCount; $timeEnd = microtime(true); $time = $timeEnd - $timeStart; if (BM_C_VERBOSE >= 10) { echo '<hr>'; echo $sqltext . '<br />'; echo $time; echo '</hr>'; } if ($this->application->debug) { bmTools::pushProfile('sql', [$sqltext, $time]); } if ($result) { return $result; } else { error_log("-----"); error_log("-- MySQL error:\n " . $this->mysqli->error); error_log("-- Request:\n " . $sqltext); //error_log("-- Backtrace:\n " . $sqltext); //$bt = debug_backtrace(); //error_log(var_export($bt, true)); error_log("-----\n\n"); if ($this->application->debug) { print $sqltext . "\n" . $this->mysqli->error; echo '<pre>'; } } } return false; }
public function addObjectImage($imageGroup, $file, $local = false) { $name = $type = $tmp_name = $error = $size = []; extract($file); if (UPLOAD_ERR_NO_FILE != $error) { $errorMessage = $this->_isUploadFile($error); if ($errorMessage) { return $errorMessage; } $nameFile = $name; $nameFile = pathinfo($nameFile); $extensionFile = mb_strtolower($nameFile['extension']); $extensionFile = $extensionFile == 'jpeg' ? 'jpg' : $extensionFile; $nameFile = $nameFile['filename']; $tmpNameFile = $tmp_name; $sizeFile = $size; $fileName = sha1(time() . sha1($nameFile)) . '.' . $extensionFile; $fileSub = mb_substr($fileName, 0, 2); $folder = rtrim(documentRoot, '/') . BM_C_IMAGE_FOLDER . $imageGroup . '/originals/' . $fileSub . '/'; if (!is_dir($folder)) { mkdir($folder, 0777, true); bmTools::chmodPath(BM_C_IMAGE_FOLDER . $imageGroup . '/originals/' . $fileSub, 0777); } if ($local) { if (!copy($tmpNameFile, $folder . $fileName)) { return "Файл не смог загрузиться в ({$folder})"; } } else { if (!move_uploaded_file($tmpNameFile, $folder . $fileName)) { return "Файл не смог загрузиться в ({$folder})"; } } chmod($folder . $fileName, 0777); list($width, $height) = getimagesize($folder . $fileName); $image = new bmImage($this->application); $image->name = $nameFile; $image->caption = $nameFile; $image->fileName = $fileName; $image->size = $sizeFile; $image->width = $width; $image->height = $height; $image->save(); $image->addLinkObject($this->objectName, $this->properties['identifier'], $imageGroup); return $image; } return null; }