public function ryp_insert($table, $rows = null, $header = null) { try { $sql = "INSERT INTO " . $table; $row = null; $value = null; foreach ($rows as $key => $nilainya) { # code... $row .= "," . $key; $value .= ", :" . $key; } $sql .= "(" . substr($row, 1) . ")"; $sql .= "VALUES(" . substr($value, 1) . ")"; $stmt = parent::prepare($sql); $stmt->execute($rows); $rowcount = $stmt->rowCount(); if ($rowcount != 0) { echo "<script> alert('Simpan Data Sukses {$rowcount}');\n\t\twindow.location.assign('{$header}');</script>"; } else { echo "<script> alert('Simpan Data Error, Data Sudah Ada {$rowcount}'); </script>"; } if ($header != null) { //session_start(); //$_SESSION['pesan']="SIMPAN DATA TABEL $table SUKSES"; header("location:" . $header); } return $rowcount; } catch (PDOException $e) { echo "<script> alert('Simpan Data Gagal'); </script>"; } }
public function CropAndCreate($fileName, $top, $left, $publicCanvasWidth, $publicCanvasHeight) { //set basic variables //$newFileName is using the set index e.g. [index]jacobclausen_[timestamp]1785645465.jpg $newFileName = $this->fileNameIndex . time() . '.jpg'; //make sure we actually have a the temporarily uploaded file to work with if ($fileName != '' && substr($fileName, 0, 3) == 'tmp') { //even if its unlikely... let's check if we have a file with this exact name since earlier. if (file_exists($this->outputPath . $newFileName)) { unlink($this->outputPath . $newFileName); } //chmod the file to ensure working conditions with it chmod($this->tmpPath . $fileName, 0755); //get the original file dimensions list($width, $height) = getimagesize($this->tmpPath . $fileName); //create the canvas $imageCanvas = imagecreatetruecolor($this->canvasWidth, $this->canvasHeight); //set the custom background color in case of "white space" in the new image $backgroundColor = imagecolorallocate($imageCanvas, $this->canvasBG[0], $this->canvasBG[1], $this->canvasBG[2]); imagefill($imageCanvas, 0, 0, $backgroundColor); $image = imagecreatefromjpeg($this->tmpPath . $fileName); //top and left margins accurate $newTop = $top * ($this->canvasHeight / $publicCanvasHeight); $newLeft = $left * ($this->canvasWidth / $publicCanvasWidth); //make adjustments to our image if ($this->imageCrop == 1) { imagecopyresampled($imageCanvas, $image, $newLeft, $newTop, 0, 0, $width, $height, $width, $height); } elseif ($this->imageCrop == 2) { //calculate the new height and keep the image proportinal $newHeight = $height * ($this->canvasWidth / $width); imagecopyresampled($imageCanvas, $image, $newLeft, $newTop, 0, 0, $this->canvasWidth, $newHeight, $width, $height); } elseif ($this->imageCrop == 3) { //calculate the new width and keep the image proportinal $newWidth = $width * ($this->canvasHeight / $height); imagecopyresampled($imageCanvas, $image, $newLeft, $newTop, 0, 0, $newWidth, $this->canvasHeight, $width, $height); } //finally create the image if (imagejpeg($imageCanvas, $this->outputPath . $newFileName, $this->quality)) { //check if this image should be added to the database if ($this->addToDB === true) { $con = new DBConnect(); try { $stmt = $con->prepare('INSERT INTO images(image_name) VALUES(?)'); $stmt->execute(array($newFileName)); } catch (PDOException $e) { $this->output = $e; } } //return the filename return $newFileName; //finally remove the temporarily image unlink($this->tmpPath . $fileName); } } }