public function uploadFile($replaceWhiteSpaceWith = NULL) { Trace::output(self::$traceID, "uploadFile", func_get_args()); //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, 'result' => array(), "func" => "uploadFile"); //---------------------------------------------------------- $upload = $this->uploadClass->post(false); //---------------------------------------------------------- if (is_null($upload["files"][0]->error)) { $orig_path = urldecode(GenFun::get_local_url($upload['files'][0]->url)); //---------------------------------------------------------- $oldName = $upload["files"][0]->name; //---------------------------------------------------------- $newName = is_null($replaceWhiteSpaceWith) ? $oldName : str_replace(' ', '_', $oldName); $arr = explode(".", $newName); $ext = $arr[sizeof($arr) - 1]; $newName = stripslashes($arr[0]); //---------------------------------------------------------- if (!is_null($replaceWhiteSpaceWith)) { $newName = preg_replace('/[^a-z_0-9-]*/i', '', $newName); } //---------------------------------------------------------- $path = FileFolder::getPathFromFile($orig_path); //---------------------------------------------------------- $path = $path . $newName . "." . $ext; //---------------------------------------------------------- rename($orig_path, $path); //---------------------------------------------------------- $local_url = $path; //---------------------------------------------------------- //$hash = MySQL::getNextInsertID('files'); //---------------------------------------------------------- //if (is_object($hash)) return $hash; //---------------------------------------------------------- //$new_local_url = FileFolder::moveToFolder($local_url, $hash."/"); //---------------------------------------------------------- //$upload['files'][0]->url = GenFun::get_full_url($new_local_url); //---------------------------------------------------------- $chk = Upload::insertFile($newName . "." . $ext, json_encode($upload)); //---------------------------------------------------------- if ($chk['bool']) { $hash = $chk['row']['hash']; //---------------------------------------------------------- if (is_object($hash)) { return $hash; } //---------------------------------------------------------- $this->url_local = FileFolder::moveToFolder($local_url, $this->appendToDir . $hash . "/"); //---------------------------------------------------------- $upload['hash'] = $hash; $chk['files'] = $upload['files']; $chk['value'] = $chk['insert_id']; $chk['hash'] = $hash; unset($chk['insert_id']); unset($chk['row']); } } else { $chk = $upload; } return $chk; }
public function fileFromCrop() { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, "func" => "fileFromCrop"); //---------------------------------------------------------- $this->src = urldecode($this->src); //---------------------------------------------------------- if (strrpos($this->src, "://") !== false) { $this->src = GenFun::get_local_url($this->src); } else { $this->src = Import::getImportPath() . $this->src; } //---------------------------------------------------------- clearstatcache(); //---------------------------------------------------------- if (!file_exists($this->src)) { $chk['bool'] = false; $chk['message'] = "{$this->src} does not exist"; return $chk; } //---------------------------------------------------------- $what = getimagesize($this->src); //---------------------------------------------------------- $ratio = $this->curWidth / $what[0]; $this->coor['w'] = $this->coor['w'] / $ratio; $this->coor['h'] = $this->coor['h'] / $ratio; //---------------------------------------------------------- $this->coor['x'] = $this->coor['x'] / $ratio; $this->coor['y'] = $this->coor['y'] / $ratio; //---------------------------------------------------------- if (is_null($this->width)) { $this->width = $this->coor['w']; } if (is_null($this->height)) { $this->height = $this->coor['h']; } //---------------------------------------------------------- $jpeg_quality = 100; //---------------------------------------------------------- if (is_null($this->src)) { $chk['bool'] = false; $chk['message'] = "src is undefined"; return $chk; } //---------------------------------------------------------- $name = explode("/", $this->src); $name = end($name); $name = substr($name, 0, -4); $name = str_replace(' ', '_', $name); //---------------------------------------------------------- switch (strtolower($what['mime'])) { case 'image/png': $img_r = imagecreatefrompng($this->src); $ext = ".png"; break; case 'image/jpeg': $img_r = imagecreatefromjpeg($this->src); $ext = ".jpg"; break; case 'image/gif': $img_r = imagecreatefromgif($this->src); $ext = ".gif"; break; case 'image/jpg': $img_r = imagecreatefromjpeg($this->src); $ext = ".jpg"; break; default: $chk['bool'] = false; $chk['message'] = "ext is not accepted!!!"; return $chk; } //---------------------------------------------------------- $dst_r = ImageCreateTrueColor($this->width, $this->height); //---------------------------------------------------------- imagecopyresampled($dst_r, $img_r, 0, 0, $this->coor['x'], $this->coor['y'], $this->width, $this->height, $this->coor['w'], $this->coor['h']); //---------------------------------------------------------- $hash = MySQL::getNextInsertID('files'); //---------------------------------------------------------- if (is_object($hash)) { return $hash; } //---------------------------------------------------------- $name = $name . "_crop" . $ext; //---------------------------------------------------------- $filePath = ProjectGlobal::$filesLocalPath . $name; //---------------------------------------------------------- header('Content-type: image/jpeg'); imagejpeg($dst_r, $filePath, $jpeg_quality); //---------------------------------------------------------- $filePath = FileFolder::moveToFolder($filePath, $hash . "/"); //---------------------------------------------------------- $chk['file'] = GenFun::get_full_url($filePath); $chk['rel'] = $filePath; $chk['src'] = $this->src; $chk['ratio'] = $ratio; $chk['result'] = Upload::insertFile($hash . "/" . $name); //---------------------------------------------------------- return $chk; }