function crop400($file, $file_name, $des) { require_once "lib/ImageManipulator.php"; $im = new ImageManipulator($file); $x1 = 0; $y1 = 0; $x2 = 400; $y2 = 300; $im->crop($x1, $y1, $x2, $y2); // takes care of out of boundary conditions automatically $im->save($des . $file_name); }
function crop5x3($file, $file_name, $des, $width) { require_once "lib/ImageManipulator.php"; $im = new ImageManipulator($file); $x1 = 0; $y1 = 0; $height = round($width * 3 / 5); $x2 = $width; $y2 = $height; $im->crop($x1, $y1, $x2, $y2); // takes care of out of boundary conditions automatically $im->save($des . $file_name); }
$fileExtension = strrchr($file['name'], "."); // check if file Extension is on the list of allowed ones if (in_array($fileExtension, $validExtensions)) { $newName = $user_id; $dotPos = strrpos($file['name'], '.'); $extension = substr($file['name'], $dotPos + 1); $manipulator = new ImageManipulator($file['tmp_name']); $width = $manipulator->getWidth(); $height = $manipulator->getHeight(); $centreX = round($width / 2); $centreY = round($height / 2); // our dimensions will be 200x130 $x1 = $centreX - 200; // 200 / 2 $y1 = $centreY - 200; // 130 / 2 $x2 = $centreX + 200; // 200 / 2 $y2 = $centreY + 200; // 130 / 2 // center cropping to 200x130 $newImage = $manipulator->resample(400, 400, true); //$manipulator2 = new ImageManipulator($newImage); //$newImage2 = $manipulator->crop($x1, $y1, $x2, $y2); // saving file to uploads folder $manipulator->save(WWW_ROOT . DS . 'uploads' . DS . 'users' . DS . $newName . "." . $extension); //echo 'Done ...'; } else { //echo 'You must upload an image...'; } });
try { $id = isset($_GET['id']) ? $_GET['id'] : ''; $recipeId = isset($_GET['recipeId']) ? $_GET['recipeId'] : ''; if (!isset($_GET['action'])) { if (!empty($_FILES)) { $recipeImageId = $db->querySingle('SELECT Z_PK FROM ZRECIPEIMAGE ORDER BY Z_PK DESC LIMIT 1') + 1; $validExtensions = array('.jpg', '.jpeg', '.gif', '.png', '.JPG', '.JPEG'); // get extension of the uploaded file $fileExtension = strrchr($_FILES['file']['name'], "."); // check if file Extension is on the list of allowed ones if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = time() . '_'; $manipulator = new ImageManipulator($_FILES['file']['tmp_name']); $db->exec('INSERT INTO ZRECIPEIMAGE (ZURL, ZRECIPE) VALUES ("images/' . $recipeImageId . $fileExtension . '", ' . $recipeId . ')'); // saving file to uploads folder $manipulator->save('../images/' . $recipeImageId . $fileExtension); echo json_encode(array('id' => $recipeImageId, 'url' => 'images/' . $recipeImageId . $fileExtension, 'alt' => '')); } else { } } } else { switch ($_GET['action']) { case 'select': $recipeImage = $db->querySingle('SELECT * FROM ZRECIPEIMAGE WHERE ZRECIPE=' . $recipeId . ' and ZPRESENTATION=1', true); if (count($recipeImage) > 0) { $db->exec('UPDATE ZRECIPEIMAGE SET ZPRESENTATION=0 WHERE Z_PK=' . $recipeImage['Z_PK']); } $db->exec('UPDATE ZRECIPEIMAGE SET ZPRESENTATION=1 WHERE Z_PK=' . $id); $recipeImageResults = $db->query('SELECT * FROM ZRECIPEIMAGE WHERE ZRECIPE = ' . $recipeId); $recipeImages = array(); while ($recipeImage = $recipeImageResults->fetchArray()) {
if (strlen($_POST['edit-password']) > 0 && strlen($_POST['edit-password']) < 4) { $notice .= "password terlalu pendek min 4 karakter" . "<br/>"; } } } if (isset($_FILES["editfoto"])) { if (strlen($_FILES["editfoto"]["tmp_name"]) > 0 && $_FILES["editfoto"]["error"] == 0) { $tmp_name = $_FILES["editfoto"]["tmp_name"]; $name = $_FILES["editfoto"]["name"]; $ext = pathinfo($name, PATHINFO_EXTENSION); $name = uniqid() . "." . $ext; $im = new ImageManipulator($_FILES['editfoto']['tmp_name']); $im->resample(240, 320, false); switch ($ext) { case 'jpg': $im->save('../img/' . $name, IMAGETYPE_JPEG); break; case 'png': $im->save('../img/' . $name, IMAGETYPE_PNG); break; default: $im->save('../img/' . $name, IMAGETYPE_JPEG); break; } $foto = "/img/" . $name; $sql = "UPDATE `karyawan` SET `foto_karyawan` = '" . $foto . "' WHERE `karyawan_id` = '" . $_SESSION['karyawan'] . "';"; $stmt = $dbh->prepare($sql); $stmt->execute(); $notice .= "foto berhasil di rubah" . "<br/>"; $_SESSION['foto'] = $foto; } else {
require_once '../helpers/ImageManipulator.php'; for ($i = 0; $i < count($_FILES['images']['tmp_name']); $i++) { if (!empty($_FILES['images']['name'][$i])) { // get uploded file type $file_name = $_FILES['images']['name'][$i]; if (is_valid_type($file_name, array('jpg', 'png', 'jpeg'))) { if (file_exists('../uploaded/products/' . $file_name)) { $file_name = md5(date('h:m:s:i')) . '_' . $file_name; } if ($i == 0) { $img = new ImageManipulator($_FILES['images']['tmp_name'][$i]); $newimg = $img->resample(285, 380); $img->save('../uploaded/products/' . 'preview_' . $file_name); $img2 = new ImageManipulator($_FILES['images']['tmp_name'][$i]); $newimg = $img2->resample(50, 67); $img2->save('../uploaded/products/' . 'cart_' . $file_name); } $move = move_uploaded_file($_FILES['images']['tmp_name'][$i], "../uploaded/products/" . $file_name); // var_dump($move); die(); if ($move) { $uplaoded_files[$i] = $file_name; } } else { header("Location: add_product.php?msg=invalid"); die; } } } } $conn->beginTransaction(); try {
/** * Método para manipulação da foto do perfil * Este método utiliza uma classe externa que não foi criada por mim * @return bool */ protected function uploadFoto() { if (Input::exists('files')) { $fotoperfil = isset($_FILES[$this->colunaImagem]) ? $_FILES[$this->colunaImagem] : null; if ($fotoperfil['error'] > 0) { //echo 'Nenhuma imagem enviada.<br>'; if (isset($_POST['webcam_photo']) && $_POST['webcam_photo'] != '') { $this->uploadWebcam(); } } else { // array com extensões válidas $validExtensions = array('.jpg', '.jpeg'); // pega a extensão do arquivo enviado $fileExtension = strrchr($fotoperfil['name'], "."); // testa se extensão é permitida if (in_array($fileExtension, $validExtensions)) { $manipulator = new ImageManipulator($fotoperfil['tmp_name']); // o tamanho da imagem poderia ser 800x600 $width = $manipulator->getWidth(); $height = $manipulator->getHeight(); // Encontrando o centro da imagem $centreX = round($width / 2); // 400 $centreY = round($height / 2); //300 // Define canto esquerdo de cima if ($width > $height) { // Parâmetros caso a imagem fornecida seja no formato paisagem $x1 = $centreX - $centreY; // 400 - 300 = 100 "Topo esquerdo X" $y1 = 0; // "Topo esquerdo Y" // Define canto direito de baixo $x2 = $centreX + $centreY; // 400 + 300 = 700 / 2 "Base X" $y2 = $centreY * 2; // 300 * 2 = 600 "Base Y" } else { // Parâmetros caso a imagem não seja no formato paisagem $y1 = $centreY - $centreX; // 400 - 300 = 100 "Topo esquerdo X" $x1 = 0; // "Topo esquerdo Y" // Define canto direito de baixo $y2 = $centreX + $centreY; // 400 + 300 = 700 / 2 "Base X" $x2 = $centreX * 2; // 300 * 2 = 600 "Base Y" } // corta no centro 200x200 $manipulator->crop($x1, $y1, $x2, $y2); // redimensiona a imagem para 400x400 $manipulator->resample(400, 400, true); $manipulator->save(IMG_UPLOADS_FOLDER . $this->arquivoTemp); $this->fotoEnviada = true; } else { $this->fotoEnviada = false; } } } }
if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = time() . '_'; $manipulator = new ImageManipulator($_FILES['picture']['tmp_name']); $manipulator->resample(500, 500); $width = $manipulator->getWidth(); $height = $manipulator->getHeight(); $centreX = round($width / 2); $centreY = round($height / 2); $x1 = $centreX - 150; $y1 = $centreY - 150; $x2 = $centreX + 150; $y2 = $centreY + 150; $newImage = $manipulator->crop($x1, $y1, $x2, $y2); // saving file to uploads folder $picturefilename = $newNamePrefix . $_FILES['picture']['name']; $manipulator->save($portal_path_root . '/../private/directory/images/employees/' . $picturefilename); } } else { $picturefilename = $currentpicture; } if ($id != "new") { //Process the Discipline Report if ($_FILES['discipline']['name']) { //Upload File to Server $validExtensions = array('.doc', '.DOC', '.docx', '.DOCX', '.pdf', '.PDF'); $fileExtension = strrchr($_FILES['discipline']['name'], "."); if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = time() . '$_$'; $disfilename = $newNamePrefix . $_FILES['discipline']['name']; if (!move_uploaded_file($_FILES['discipline']['tmp_name'], $portal_path_root . '/../private/directory/discipline/' . $disfilename)) { echo "The file was not uploaded";
die; } //function used to know file type require '../helpers/filetype.php'; $type = get_type($img_name); //class used to resize images require_once '../helpers/ImageManipulator.php'; //to make random name $randomstring = substr(str_shuffle("1234567890abcdefghijklmnopqrstuvwxyz"), 0, 15); $img_name = $randomstring . ".{$type}"; $newName = time() . '_'; $img = new ImageManipulator($_FILES['file']['tmp_name']); //resize image $newimg = $img->resample(950, 400); //put image in file "image" $img->save('image/' . $img_name); } /* update in database */ require 'connection.php'; $query = $conn->prepare("UPDATE menu SET cat_name=?,cat_name_ar=?,image=? WHERE id = ?"); $query->bindValue(1, $menu, PDO::PARAM_STR); $query->bindValue(2, $menu_ar, PDO::PARAM_STR); $query->bindValue(3, $img_name, PDO::PARAM_STR); $query->bindValue(4, $id, PDO::PARAM_INT); if ($query->execute()) { header("location: show_menu.php?msg=data_updated"); die; } header("location: edit_menu.php?msg=error_data&id={$id}");
public static function getGalleryPicture($img) { $imageName = 'GP_' . $img; $targetFile = '../../../View/img/Upload/galeri/' . $img; $squareImg = '../../../View/img/Upload/galeri/' . $imageName; $finalImg = 'http://localhost/SIMasjid/View/img/Upload/galeri/' . $imageName; if (copy($targetFile, $squareImg)) { $size = 0; $imS = new ImageManipulator($squareImg); if ($imS->getWidth() != $imS->getHeight()) { if ($imS->getWidth() < $imS->getHeight()) { $size = $imS->getWidth(); } else { $size = $imS->getHeight(); } $centreX = round($imS->getWidth() / 2); $centreY = round($imS->getHeight() / 2); $x1 = $centreX - $size / 2; $y1 = $centreY - $size / 2; $x2 = $centreX + $size / 2; $y2 = $centreY + $size / 2; $imS->crop($x1, $y1, $x2, $y2); $imS->save($squareImg); unlink($targetFile); } } else { $finalImg = null; } return $finalImg; }
public function createThumbnail() { $im = new ImageManipulator($this->pathProfilePic . $this->get('profilepic')); $centerX = round($im->getWidth() / 2); $centerY = round($im->getHeight() / 2); if ($im->getWidth() >= $im->getHeight()) { $x1 = $centerX - $centerY; $y1 = 0; $x2 = $centerX + $centerY; $y2 = $im->getHeight(); } else { $x1 = 0; $y1 = $centerY - $centerX; $x2 = $im->getWidth(); $y2 = $centerY + $centerX; } $im->crop($x1, $y1, $x2, $y2); // takes care of out of boundary conditions automatically $im->resample(50, 50, true); $im->save($this->pathProfilePicThumb . $this->get('profilepic')); }
<?php include_once "../config.php"; $banner = $admin_database->cleanXSS(@$_POST["banner"]); $yAxis = $admin_database->cleanXSS(@$_POST['yAxis']); //$banner_location = $GLOBAL_BANNER_TNB . $banner; $banner_location = "../../uploads/banner/thumbnail/" . $banner; $im = new ImageManipulator($banner_location); //fb($im); $x1 = 0; $y1 = $yAxis; $x2 = 780; $y2 = 390; $im->crop($x1, $y1, $x2, $y2); //fb($im); $im->save($banner_location);
if ($_FILES['fileToUpload']['size'] >= $maxsize || $_FILES['fileToUpload']['size'] == 0) { echo "File too large. File must be less than 2 megabytes"; } else { if ($_FILES['fileToUpload']['error'] > 0) { echo "Error: " . $_FILES['fileToUpload']['error'] . "<br />"; } else { // array of valid extensions $validExtensions = array('.jpg', '.jpeg', '.gif', '.png'); // get extension of the uploaded file $fileExtension = strrchr($_FILES['fileToUpload']['name'], "."); // check if file Extension is on the list of allowed ones if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = 'conId_' . $contactId . '_'; $manipulator = new ImageManipulator($_FILES['fileToUpload']['tmp_name']); // resizing to 200x200J227V-G3HWJ $newImage = $manipulator->resample(200, 200); // saving file to uploads folder $manipulator->save('uploads/' . $newNamePrefix . $_FILES['fileToUpload']['name']); if (isset($trainer['picture'])) { $target = $trainer['picture']; unlink($target); } $piclocation = "uploads/" . $newNamePrefix . $_FILES['fileToUpload']['name']; $sqlUpdate = "UPDATE trainers SET picture = '{$piclocation}' WHERE contactId = '{$contactId}'"; $dbconn->query($sqlUpdate); header("location:trProfile.php?contactId={$contactId}"); } else { echo 'You must upload an image...'; } } }
<?php //include ImageManipulator class require_once 'ImageManipulator.php'; //get image file name $image = explode("/", $_POST['image']); $image = end($image); include 'zzzzz.php'; $result = mysqli_query($con, "SELECT username from users WHERE userID=" . $_POST['userID']); $row = mysqli_fetch_array($result); //check if file Extension is on the list of allowed ones $manipulator = new ImageManipulator("userInfo/" . $row['username'] . "/pics/" . $image); //get the x1, y1, x2, y2 for the new picture $x1 = $_POST["x"]; $y1 = $_POST["y"]; $x2 = $x1 + $_POST["width"]; $y2 = $y1 + $_POST["height"]; //crop $newImage = $manipulator->crop($x1, $y1, $x2, $y2); $newNamePrefix = time() . '_'; //saving file to proper folder $manipulator->save("userInfo/" . $row['username'] . "/pics/" . $newNamePrefix . $image); mysqli_query($con, "UPDATE users SET profPicLoc='" . $newNamePrefix . $image . "' WHERE userID=" . $_POST['userID'] . ""); echo "saved";
<?php include_once "../config.php"; $banner = $admin_database->cleanXSS(@$_POST["banner"]); $yAxis = $admin_database->cleanXSS(@$_POST['yAxis']); //$banner_location = $GLOBAL_BANNER_TNB . $banner; $banner_location = "../../uploads/banner/thumbnail/" . $banner; $im = new ImageManipulator($banner_location); //fb($im); $x1 = 0; $y1 = $yAxis; // $x2 = 780; // $y2 = 390; $x2 = 500; $y2 = 250; $im->crop($x1, $y1, $x2, $y2); //fb($im); $im->save($banner_location); // for SNS link image ---------------------------------- $snsimag_destination = "../../uploads/banner/forsns/" . $banner; $im2 = new ImageManipulator($banner_location); $im2->resample(250, 125); $im2->save($snsimag_destination);
$dotPos = strrpos($file['name'], '.'); $extension = substr($file['name'], $dotPos); $manipulator = new ImageManipulator($file['tmp_name']); $width = $manipulator->getWidth(); $height = $manipulator->getHeight(); $centreX = round($width / 2); $centreY = round($height / 2); // our dimensions will be 200x130 $x1 = $centreX - 200; // 200 / 2 $y1 = $centreY - 200; // 130 / 2 $x2 = $centreX + 200; // 200 / 2 $y2 = $centreY + 200; // 130 / 2 // center cropping to 200x130 $newImage = $manipulator->resample(400, 400, true); // saving file to uploads folder $manipulator->save(WWW_ROOT . DS . 'uploads' . DS . $_POST['user_id'] . DS . $_POST['post_id'] . $extension); echo json_encode(true); } else { echo json_encode(false); } } if (!empty($_POST['url'])) { $dotPos = strrpos($_POST['url'], '.'); $extension = substr($_POST['url'], $dotPos); copy($_POST['url'], WWW_ROOT . DS . 'uploads' . DS . $_POST['user_id'] . DS . $_POST['post_id'] . $extension); } });
die("Return Code: " . $_FILES["file"]["error"] . "<br>"); } else { // echo "Upload: " . $_FILES["file"]["name"] . "<br>"; // echo "Type: " . $_FILES["file"]["type"] . "<br>"; // echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; // echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; $ran = gen_random_string(8); $filename = $version . "_" . $ran . "." . $extension; // move_uploaded_file($_FILES["file"]["tmp_name"], "../../slider_images/" . $pname.".".$extension); // echo "Stored in: " . "facultyImages/" . $faculty_name.".".$extension; // $imageurl="slider_images/" . $pname.".".$extension; $manipulator = new ImageManipulator($_FILES['file']['tmp_name']); // resizing to 200x200 $newImage = $manipulator->resample(206, 291); // saving file to uploads folder $manipulator->save('../../horizonImages/' . $filename); $imageurl = "horizonImages/" . $filename; if (file_exists('../../' . $object->horizon_photo_url)) { unlink('../../' . $object->horizon_photo_url); } } } else { die("Invalid file extension or file size grater then 2MB. "); } } else { $imageurl = $object->horizon_photo_url; } $ho = new Horizon_IssueClass($id, $version, $date, $issueURL, $imageurl); echo $ho->updateHorizonIssue(); $l = new site_log(NULL, NULL, $_SESSION['user']->username, $_SERVER['REMOTE_ADDR'], $id . " horizon issue updated"); $l->insertlog();
public function addEventNew() { if ($_FILES['fileToUpload']['error'] > 0) { echo "Error: " . $_FILES['fileToUpload']['error'] . "<br />"; } else { // array of valid extensions $validExtensions = array('.jpg', '.jpeg', '.gif', '.png'); // get extension of the uploaded file $fileExtension = strrchr($_FILES['fileToUpload']['name'], "."); // check if file Extension is on the list of allowed ones if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = time() . '_946X381_'; $newNamePrefix1 = time() . '_253X190_'; $manipulator = new ImageManipulator($_FILES['fileToUpload']['tmp_name']); $manipulator1 = new ImageManipulator($_FILES['fileToUpload']['tmp_name']); // resizing Photos $newImage = $manipulator->resample(946, 381); $newImage1 = $manipulator1->resample(253, 190); // saving file to uploads folder $manipulator->save('./img/' . $newNamePrefix . $_FILES['fileToUpload']['name']); $manipulator1->save('./img/' . $newNamePrefix1 . $_FILES['fileToUpload']['name']); $photo = $newNamePrefix . $_FILES['fileToUpload']['name']; $title = addslashes(trim($_POST['title'])); $daytime = addslashes(trim($_POST['daytime'])); $target = addslashes(trim($_POST['target'])); $venue = addslashes(trim($_POST['venue'])); $description = addslashes(trim($_POST['body'])); $cost = addslashes(trim($_POST['cost'])); $days = addslashes(trim($_POST['days'])); $month = addslashes(trim($_POST['month'])); $sql = "INSERT INTO `events`(`title`, `daytime`, `target`, `venue`, `cost`, `description`, `photo`,days,month) \n\t\t\tVALUES ('{$title}','{$daytime}','{$target}','{$venue}','{$cost}','{$description}','{$photo}','{$days}','{$month}')"; $sql = Database::performQuery($sql); $content = ' <section id="content"> <div class="content-wrap"> <div class="container clearfix"> <div class="fancy-title title-border topmargin"> <h4>Admin Dashboard</h4> </div> <a href="' . BASE_URL . '/?go=manageRsvp" class="button button-desc button-rounded button-red center">Manage RSVPs<span></span></a> <a href="' . BASE_URL . '/?go=manageBlog" class="button button-desc button-rounded button-green center">Manage Blog<span></span></a> <a href="' . BASE_URL . '/?go=manageEvents" class="button button-desc button-rounded button-teal center">Manage Events<span></span></a> </div> <div class="alert alert-success"> <strong>Successfully!</strong> Added Event. </div> </div> </div> </section> '; } else { $content = ' <section id="content"> <div class="content-wrap"> <div class="container clearfix"> <div class="fancy-title title-border topmargin"> <h4>Admin Dashboard</h4> </div> <a href="' . BASE_URL . '/?go=manageRsvp" class="button button-desc button-rounded button-red center">Manage RSVPs<span></span></a> <a href="' . BASE_URL . '/?go=manageEvents" class="button button-desc button-rounded button-green center">Manage Events<span></span></a> <a href="' . BASE_URL . '/?go=manageEvent" class="button button-desc button-rounded button-teal center">Manage Events<span></span></a> </div> <div class="alert alert-danger"> <strong>Oooops!</strong> Failed to add event because we failed to process the image.. </div></div> </div> </section> '; } } return $content; }
$tempr = explode(".", $_FILES["rfile"]["name"]); $rextension = end($tempr); // echo "Upload: " . $_FILES["cfile"]["name"] . "<br />"; // echo "Type: " . $_FILES["cfile"]["type"] . "<br />"; // echo "Size: " . ($_FILES["cfile"]["size"] / 1024) . " Kb<br />"; // echo "Temp file: " . $_FILES["cfile"]["tmp_name"] . "<br />"; move_uploaded_file($_FILES["rfile"]["tmp_name"], "../../alumni_resume/" . $username . "." . $rextension); // echo "Stored in: " . "../resumes/" . $_FILES["cfile"]["name"]; $rurl = "alumni_resume/" . $username . "." . $rextension; } else { die("Invalid file extension or file size grater then 2MB."); } } else { $rurl = NULL; } $manipulator->save('../../alumni_photos/' . $username . "." . $extension); $imageurl = "alumni_photos/" . $username . "." . $extension; } } else { die("Invalid photo file"); } } else { die("Choose photo."); } $alu = new Alumni_Detail($username, $fname, $lname, $email, $linkedin_id, $rurl, $batch, $imageurl, $password, "1"); $res = $alu->InsertAlumni(); if ($res != 1) { if ($_FILES["file"]["name"]) { if (file_exists('../../alumni_photos/' . $username . "." . $extension)) { unlink('../../alumni_photos/' . $username . "." . $extension); }
public function DoRegPhoto() { if ($_FILES['photo']['error'] > 0) { echo "Error: " . $_FILES['photo']['error'] . "<br />"; } else { // array of valid extensions $validExtensions = array('.jpg', '.jpeg', '.gif', '.png'); // get extension of the uploaded file $fileExtension = strrchr($_FILES['photo']['name'], "."); // check if file Extension is on the list of allowed ones if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = time() . '_150X150_'; $newNamePrefix1 = time() . '_400X400_'; $newNamePrefix2 = time() . '_73X73_'; $manipulator = new ImageManipulator($_FILES['photo']['tmp_name']); $manipulator1 = new ImageManipulator($_FILES['photo']['tmp_name']); $manipulator2 = new ImageManipulator($_FILES['photo']['tmp_name']); // resizing $newImage = $manipulator->resample(150, 150); $newImage1 = $manipulator1->resample(400, 400); $newImage2 = $manipulator2->resample(73, 73); // saving file to uploads folder $manipulator->save('assets/t4g/images/user/' . $newNamePrefix . $_FILES['photo']['name']); $manipulator1->save('assets/t4g/images/user/' . $newNamePrefix1 . $_FILES['photo']['name']); $manipulator2->save('assets/t4g/images/user/' . $newNamePrefix2 . $_FILES['photo']['name']); //Update user details with photo location $photo = $newNamePrefix . $_FILES['photo']['name']; $email = $_SESSION['email']; $sql = "UPDATE user SET photo ='{$photo}' WHERE email LIKE '{$email}'"; Database::performQuery($sql); redirect_to(BASE_URL . '/RegAddress.html'); } else { $_SESSION['err'][] = "<li>Failed to process image.</li>"; $_SESSION['err'][] = "<li>Allowed image types are .jpg,.jpeg,.png and .gif</li>"; $_SESSION['err'][] = "<li>Please upload a new photo.</li>"; redirect_to(BASE_URL . '/RegPhoto.html'); } } }
if (in_array($fileExtension, $validExtensions)) { $uploaddir = 'photos/'; $newNamePrefix = time() . '_'; $Photo = $uploaddir . $newNamePrefix . $_FILES['myphoto']['name']; $manipulator = new ImageManipulator($_FILES['myphoto']['tmp_name']); $newImage = $manipulator->resample(250, 250); $width = $manipulator->getWidth(); $height = $manipulator->getHeight(); $centreX = round($width / 2); $centreY = round($height / 2); $x1 = $centreX - 125; $y1 = $centreY - 125; $x2 = $centreX + 125; $y2 = $centreY + 125; $newImage = $manipulator->crop($x1, $y1, $x2, $y2); $manipulator->save(LOCAL_PATH_ROOT . '/photos/' . $newNamePrefix . $_FILES['myphoto']['name']); $stmt = $db->prepare('UPDATE tblempall SET Photo = :Photo WHERE EmpNum = :EmpNum'); $stmt->execute(array('Photo' => $Photo, 'EmpNum' => $_SESSION['user']->EmpNum)); $_SESSION['user']->Photo = $Photo; } else { $error = 'yes'; } } ?> <!doctype html> <html class="no-js" lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Our Heroes</title> <link rel="stylesheet" href="<?php
public function addBlogNew() { if ($_FILES['fileToUpload']['error'] > 0) { echo "Error: " . $_FILES['fileToUpload']['error'] . "<br />"; } else { // array of valid extensions $validExtensions = array('.jpg', '.jpeg', '.gif', '.png'); // get extension of the uploaded file $fileExtension = strrchr($_FILES['fileToUpload']['name'], "."); // check if file Extension is on the list of allowed ones if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = time() . '_946X381_'; $newNamePrefix1 = time() . '_253X190_'; $manipulator = new ImageManipulator($_FILES['fileToUpload']['tmp_name']); $manipulator1 = new ImageManipulator($_FILES['fileToUpload']['tmp_name']); // resizing Photos $newImage = $manipulator->resample(946, 381); $newImage1 = $manipulator1->resample(253, 190); // saving file to uploads folder $manipulator->save('./img/' . $newNamePrefix . $_FILES['fileToUpload']['name']); $manipulator1->save('./img/' . $newNamePrefix1 . $_FILES['fileToUpload']['name']); $photo = $newNamePrefix . $_FILES['fileToUpload']['name']; $title = addslashes(trim($_POST['title'])); $category = addslashes(trim($_POST['category'])); $tags = explode(",", addslashes(trim($_POST['tags']))); $quote = addslashes(trim($_POST['quote'])); $body = addslashes(trim($_POST['body'])); //$created_by =$_SESSION['oauth_uid'];; $created = date('Y-m-d H:i:s'); $sql = "INSERT INTO `article`(`title`, `post`, `media`, `submitted`, `quote`, `articleCat_id`) \n\t\t\t\t\tVALUES ('{$title}','{$body}','{$photo}','{$created}','{$quote}','{$category}')"; $sql = Database::performQuery($sql); $content = ' <section id="content"> <div class="content-wrap"> <div class="container clearfix"> <div class="fancy-title title-border topmargin"> <h4>Admin Dashboard</h4> </div> <a href="' . BASE_URL . '/?go=manageRsvp" class="button button-desc button-rounded button-red center">Manage RSVPs<span></span></a> <a href="' . BASE_URL . '/?go=manageEvents" class="button button-desc button-rounded button-green center">Manage Events<span></span></a> <a href="' . BASE_URL . '/?go=manageBlog" class="button button-desc button-rounded button-teal center">Manage Blogs<span></span></a> </div> <div class="alert alert-success"> <strong>Successfully!</strong> Added Article. </div> </div> </div> </section> '; } else { $content = ' <section id="content"> <div class="content-wrap"> <div class="container clearfix"> <div class="fancy-title title-border topmargin"> <h4>Admin Dashboard</h4> </div> <a href="' . BASE_URL . '/?go=manageRsvp" class="button button-desc button-rounded button-red center">Manage RSVPs<span></span></a> <a href="' . BASE_URL . '/?go=manageEvents" class="button button-desc button-rounded button-green center">Manage Events<span></span></a> <a href="' . BASE_URL . '/?go=manageBlog" class="button button-desc button-rounded button-teal center">Manage Blogs<span></span></a> </div> <div class="alert alert-danger"> <strong>Oooops!</strong> Failed to add article because we failed to process the image.. </div></div> </div> </section> '; } } return $content; }
public function CropImageIntoFolder($target_folder, $folder_postfix, $folder_upload, $banner) { global $admin_image; list($width, $height) = getimagesize($folder_upload); $popupWidth = $width; $popupHeight = $height; $profileWidth = $width; $profileHeight = $height; $thumbnailWidth = $width; $thumbnailHeight = $height; $resizeArray["thumbnail"] = array("width" => $width, "height" => $height, "resizeWidth" => 500, "resizeHeight" => 250, "source" => $folder_upload, "quality" => 10, "square" => false, "destination" => $target_folder . "thumbnail/" . $folder_postfix); foreach ($resizeArray as $id => $value) { //while($value["width"] > $value["resizeWidth"] || $value["height"] > $value["resizeHeight"]){ if ($value["width"] > $value["resizeWidth"] || $value["width"] < $value["resizeWidth"]) { $ratio = $value["resizeWidth"] / $value["width"]; $value["height"] = $value["height"] * $ratio; $value["width"] = $value["resizeWidth"]; } $admin_image->settings($value["source"], $value["width"], $value["height"], $value["quality"], $value["square"], "", $value["destination"]); $rst = $admin_image->resize(); } // for SNS link image ---------------------------------- // echo"<script>alert('$banner')</script>"; $snsimag_destination = "../uploads/banner/forsns/" . $folder_postfix . $banner; $banner_location = "../uploads/banner/thumbnail/" . $folder_postfix . $banner; $im3 = new ImageManipulator($banner_location); $im3->resample(250, 125); $im3->save($snsimag_destination); }
// echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; // echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; // if (file_exists("../../slider_images/" . $pname.".".$extension)) // { // die($pname.".".$extension. " already exists. "); // } // else // { // move_uploaded_file($_FILES["file"]["tmp_name"], "../../slider_images/" . $pname.".".$extension); // echo "Stored in: " . "facultyImages/" . $faculty_name.".".$extension; // $imageurl="slider_images/" . $pname.".".$extension; list($width, $height) = getimagesize($_FILES['file']['tmp_name']); $newwidth = $width * 350 / $height; $manipulator = new ImageManipulator($_FILES['file']['tmp_name']); // resizing to 200x200 $newImage = $manipulator->resample($newwidth, 350); // saving file to uploads folder $manipulator->save('../../slider_images/' . $pname . "." . $extension); $imageurl = "slider_images/" . $pname . "." . $extension; // } } } else { die("Sorry, Invalid file extention or file size greater than 2 MB."); } } else { die("Choose file."); } $a = new Slider_PhotoClass(NULL, $imageurl, $sc_name, $sc_caption, "0"); echo $a->UploadPhotos($imageurl, $sc_name, $sc_caption); $l = new site_log(NULL, NULL, "visitor", $_SERVER['REMOTE_ADDR'], $sc_caption . " slider photo added"); $l->insertlog();
<?php require_once 'db.php'; require_once 'imageManipulator.php'; try { $id = isset($_GET['id']) ? $_GET['id'] : ''; if (!empty($_FILES)) { $country = $db->querySingle('SELECT * FROM ZCOUNTRY WHERE Z_PK=' . $id, true); $validExtensions = array('.jpg', '.jpeg', '.gif', '.png', '.JPG', '.JPEG'); // get extension of the uploaded file $fileExtension = strrchr($_FILES['file']['name'], "."); // check if file Extension is on the list of allowed ones if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = time() . '_'; $manipulator = new ImageManipulator($_FILES['file']['tmp_name']); $db->exec('UPDATE ZCOUNTRY SET ZCOVER="images/' . $country['ZCODE'] . $fileExtension . '" WHERE Z_PK=' . $country['Z_PK']); // saving file to uploads folder $manipulator->save('../images/' . $country['ZCODE'] . $fileExtension); error_log("HERE I AM file=" . '../images/' . $country['ZCODE'] . $fileExtension); } else { } } } finally { include 'db_cleanup.php'; }
function upload_data($authuserid) { $username = "******"; // username $key = "0d5739ba0696428f885890282d3ba150"; // api key //Rackspace client $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => $username, 'apiKey' => $key)); //Authenticate client $client->authenticate(); $service = $client->objectStoreService('cloudFiles'); $container = $service->getContainer('userimages'); //Figure out the user first name and last name based on the $name variable //We must have got some dimensions to crop the images, lets get that set $profile_image_crop_x = $_POST['x']; $profile_image_crop_y = $_POST['y']; $profile_image_crop_w = $_POST['w']; $profile_image_crop_h = $_POST['h']; if ($_FILES['profile_image']['tmp_name'] != "") { $imageProcessor = new ImageManipulator($_FILES['profile_image']['tmp_name']); if ($profile_image_crop_w > 1 && $profile_image_crop_h > 1) { $croppedImage = $imageProcessor . crop($profile_image_crop_x, $profile_image_crop_y, $profile_image_crop_x + $profile_image_crop_w, $profile_image_crop_y + $profile_image_crop_h); } $imageProcessor->save($basePath . $target_profile_pic_name); //Read back the file so that we can now upload it to Rackspace CDN. //Common Meta $meta = array('Author' => $name, 'Origin' => 'FINAO Web'); $metaHeaders = DataObject::stockHeaders($meta); $data = fopen($basePath . $target_profile_pic_name, 'r+'); $container->uploadObject($target_profile_pic_name, $data, $metaHeaders); $targ_w = 150; $targ_h = 150; $jpeg_quality = 90; $profile_thumb_image = $imageProcessor->resample($targ_w, $targ_h); $imageProcessor->save($basePath . $target_profile_pic_thumb); $data = fopen($basePath . $target_profile_pic_thumb, 'r+'); $container->uploadObject($target_profile_pic_thumb, $data, $metaHeaders); } if ($_FILES['profile_bg_image']['tmp_name'] != "") { @move_uploaded_file($_FILES['profile_bg_image']['tmp_name'], 'images/uploads/profileimages/' . $target_banner_pic_name); //Common Meta $meta = array('Author' => $name, 'Origin' => 'FINAO Web'); $metaHeaders = DataObject::stockHeaders($meta); $data = fopen($basePath . $target_banner_pic_name, 'r+'); $container->uploadObject($target_banner_pic_name, $data, $metaHeaders); } }