示例#1
17
 /**
  * Método para manipulação da foto do perfil
  * Este método utiliza uma classe externa que não foi criada por mim
  */
 public function uploadFoto()
 {
     if (Input::exists('files')) {
         $fotoperfil = isset($_FILES[$this->coluna]) ? $_FILES[$this->coluna] : null;
         if ($fotoperfil['error'] > 0) {
             echo 'Nenhuma imagem enviada.<br>';
         } 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->arquivo_temp);
                 $this->foto_enviada = true;
             } else {
                 $this->foto_enviada = false;
             }
         }
     }
 }
示例#2
0
文件: ThemeFile.php 项目: saiber/www
 private function createThumbnail($fileName)
 {
     $im = new ImageManipulator($this->path . $fileName);
     if ($im->isValidImage()) {
         $size = $this->getThumbnailSize();
         $res = $im->resize($size[0], $size[1], $this->thumbnailPath . $fileName);
         return $res;
     }
     return false;
 }
示例#3
0
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);
}
示例#4
0
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);
}
示例#5
0
 public function resizeImage(ImageManipulator $resizer)
 {
     foreach ($this->getImageSizes() as $key => $size) {
         $filePath = $this->getPath($key);
         if (!file_exists(dirname($filePath))) {
             mkdir(dirname($filePath), 0777, true);
         }
         $res = $resizer->resize($size[0], $size[1], $filePath);
         if (!$res) {
             break;
         }
     }
     return $res;
 }
示例#6
0
<?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);
示例#7
0
 private function importImage(ProductImage $image, $path)
 {
     if (!$path) {
         return false;
     }
     if (@parse_url($path, PHP_URL_SCHEME)) {
         $fetch = new NetworkFetch($path);
         $path = $fetch->fetch() ? $fetch->getTmpFile() : '';
     } else {
         if (!file_exists($path)) {
             foreach (array('/tmp/import/', ClassLoader::getRealPath('public.import.')) as $loc) {
                 $p = $loc . $path;
                 if (file_exists($p)) {
                     $path = $p;
                     break;
                 }
             }
         }
         if (!file_exists($path)) {
             $path = '';
         }
     }
     if ($path) {
         $man = new ImageManipulator($path);
         if ($man->isValidImage()) {
             $image->save();
             $image->resizeImage($man);
             $image->save();
         }
     }
 }
示例#8
0
 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);
 }
示例#9
0
    require '../helpers/filevalidate.php';
    if (!validation($img_name, array('jpg', 'png', 'jpeg'))) {
        // function return false
        header("location: edit_menu.php?id={$id}&msg=error_data");
        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()) {
 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'));
 }
示例#11
0
<?php

include '../inc/config.php';
require_once 'ImageManipulator.php';
if ($_FILES) {
    $validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
    $fileExtension = strrchr($_FILES['myphoto']['name'], ".");
    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';
    }
}
?>
示例#12
0
 public function uploadProductImage()
 {
     ClassLoader::import('application.model.product.ProductImage');
     ClassLoader::import('library.image.ImageManipulator');
     $field = 'upload_' . $this->request->get('field');
     $dir = ClassLoader::getRealPath('public.upload.tmpimage.');
     // delete old tmp files
     chdir($dir);
     $dh = opendir($dir);
     $threshold = strtotime("-1 day");
     while (($dirent = readdir($dh)) != false) {
         if (is_file($dirent)) {
             if (filemtime($dirent) < $threshold) {
                 unlink($dirent);
             }
         }
     }
     closedir($dh);
     // create tmp file
     $file = $_FILES[$field];
     $tmp = 'tmp_' . $field . md5($file['tmp_name']) . '__' . $file['name'];
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
         chmod($dir, 0777);
     }
     $path = $dir . $tmp;
     move_uploaded_file($file['tmp_name'], $path);
     if (@getimagesize($path)) {
         $thumb = 'tmp_thumb_' . $tmp;
         $thumbPath = $dir . $thumb;
         $thumbDir = dirname($thumbPath);
         if (!file_exists($thumbDir)) {
             mkdir($thumbDir, 0777, true);
             chmod($thumbDir, 0777);
         }
         $conf = self::getApplication()->getConfig();
         $img = new ImageManipulator($path);
         $thumbSize = ProductImage::getImageSizes();
         $thumbSize = $thumbSize[2];
         // 1 is too small, cant see a thing.
         $img->resize($thumbSize[0], $thumbSize[1], $thumbPath);
         $thumb = 'upload/tmpimage/' . $thumb;
     } else {
         return new JSONResponse(null, 'failure', $this->translate('_error_uploading_image'));
     }
     return new JSONResponse(array('name' => $file['name'], 'file' => $tmp, 'thumb' => $thumb), 'success');
 }
 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;
 }
示例#14
0
文件: users.php 项目: Charlili/Fumblr
    exit();
});*/
$app->post('/upload/user', function () {
    //echo json_encode($_FILES);
    $user_id = $_SESSION['user']['id'];
    $file = $_FILES["SelectedFile"];
    // array of valid extensions
    $validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
    // get extension of the uploaded file
    $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);
示例#15
0
文件: upload.php 项目: TXNWG/fytme
$maxsize = 2097152;
//limit size to 2 mb
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...';
        }
示例#16
0
 public function resizeImage($source, $target, $confSuffix)
 {
     $dir = dirname($target);
     if (!file_exists($dir)) {
         mkdir($dir, 0777);
         chmod($dir, 0777);
     }
     $conf = self::getApplication()->getConfig();
     $img = new ImageManipulator($source);
     $img->setQuality($conf->get('IMG_O_Q_' . $confSuffix));
     $img->resize($conf->get('IMG_O_W_' . $confSuffix), $conf->get('IMG_O_H_' . $confSuffix), $target);
 }
示例#17
0
<?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);
示例#18
0
<?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";
示例#19
0
$objUser = new Model_User($objConnection);
$currentUser = $_SESSION[global_common::SES_C_USERINFO];
$currentPartner = $objPartner->getPartnerByUserID($currentUser[global_mapping::UserID]);
//print_r($currentPartner);
if ($_pgR["update-avatar"]) {
    $allowedExts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    if (($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/pjpeg" || $_FILES["file"]["type"] == "image/x-png" || $_FILES["file"]["type"] == "image/png") && in_array($extension, $allowedExts)) {
        if ($_FILES["file"]["error"] > 0) {
            global_common::writeLog($_FILES["file"]["error"]);
            //echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        } else {
            //if (file_exists("upload/" . $_FILES["file"]["name"]))
            //{
            $manipulator = new ImageManipulator($_FILES["file"]["tmp_name"]);
            // resizing to 200x200
            $manipulator->resample($_FILES["file"]["tmp_name"], $_FILES["file"]["type"], 200, 200);
            //echo "after";
            $fileName = global_common::FOLDER_AVATAR . $currentUser[global_mapping::UserID] . '_' . $_FILES["file"]["name"];
            $userUpdate = $objUser->getUserByID($currentUser[global_mapping::UserID]);
            $userUpdate[global_mapping::Avatar] = $fileName;
            //echo $fileName;
            //echo $userUpdate[global_mapping::IsActive];
            $result = $objUser->update($userUpdate[global_mapping::UserID], $userUpdate[global_mapping::UserName], $userUpdate[global_mapping::Password], $userUpdate[global_mapping::FullName], $userUpdate[global_mapping::BirthDate], $userUpdate[global_mapping::Address], $userUpdate[global_mapping::Phone], $userUpdate[global_mapping::Email], $userUpdate[global_mapping::Sex], $userUpdate[global_mapping::Identity], $userUpdate[global_mapping::RoleID], $userUpdate[global_mapping::UserRankID], $userUpdate[global_mapping::Avatar], $userUpdate[global_mapping::AccountID], $userUpdate[global_mapping::IsActive]);
            //echo $result;
            $_SESSION[global_common::SES_C_USERINFO] = $currentUser = $userUpdate;
            move_uploaded_file($_FILES["file"]["tmp_name"], $fileName);
            //}
            //else
            //{
示例#20
0
 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');
         }
     }
 }
示例#21
0
if ($_FILES["file"]["name"]) {
    $allowedExts = array("jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    if (($_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/pjpeg" || $_FILES["file"]["type"] == "image/x-png" || $_FILES["file"]["type"] == "image/png") && $_FILES["file"]["size"] < 2048000 && in_array($extension, $allowedExts)) {
        if ($_FILES["file"]["error"] > 0) {
            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>";
            //  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(125, 125);
            //uploading pdf
            if ($_FILES["rfile"]["name"]) {
                if ($_FILES["rfile"]["type"] == "application/pdf" && $_FILES["rfile"]["size"] < 2048000) {
                    $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 {
示例#22
0
    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;
    }
	function traiterImage( $post, $file ) {
		$extension_autorise = array("image/jpeg", "image/pjpeg", "image/bmp", "image/gif", "image/png");
		$chemin = "../../images/produit";
		
		// Le type de fichier est bien une image
		if (in_array($file["type"], $extension_autorise)) {
			$name = $file["name"];
			$ext = substr($name, strrpos($name, ".") + 1); 
			$nom_fichier = basename($name, "." . $ext);
			//$nom_fichier = $file["name"];
			
			// Pour éviter d'écraser l'ancien en cas de doublon
			$n = "";
			while(file_exists($chemin . "/" . $nom_fichier . $n . "." . $ext)) 
				$n++;
			
			$nom_fichier = $nom_fichier . $n . "." . $ext;
			
			//echo "nom fichier : " . $nom_fichier . "<br>";
			//echo "Lieu : " . $chemin . "/" . $nom_fichier . "<br>";
			
			$resultat = move_uploaded_file($file["tmp_name"], $chemin . "/" . $nom_fichier);
			if ($resultat == true) {
				
				// ----- Dimensions de l'image ----- //
				// Changement du répertoire de destination
				$rep_destination = $chemin . "/";
				$largeur_maxi = 800;
				$hauteur_maxi = 600;
				//echo $rep_destination . $nom_fichier . "<br>";
				
				$fichier_a_retailler = $rep_destination . $nom_fichier;
				$size = GetImageSize($fichier_a_retailler); 
				$largeur = $size[0];
				$hauteur = $size[1];
				
				//echo "0 largeur : " . $largeur . "<br>";
				//echo "0 hauteur : " . $hauteur . "<br>";
				$fichier_a_retailler = $rep_destination . $nom_fichier;
				
				// Redimensionnement de l'image ET création d'une vignette
				if ( $erreur == 0 && ($largeur > $largeur_maxi)) {
					
					//echo "fichier a retailler : " . $fichier_a_retailler . "<br>";
					$i = new ImageManipulator($fichier_a_retailler);
					
					$nouvelle_largeur  = $largeur_maxi;
					$nouvelle_hauteur = ($nouvelle_largeur * $hauteur) / $largeur ; // hauteur proportionnelle
					
					$i->resample($largeur_maxi, $nouvelle_hauteur);
					$filename = $rep_destination . $nom_fichier;
					//echo "--> " . $filename . "<br>";
					$i->save_jpeg($filename);
					$i->end();
					
					//$autre_chemin = "../../cartfile/im/produit";
					//copy($rep_destination . $nom_fichier, $autre_chemin . "/" . $nom_fichier);
					
					$size = GetImageSize($filename); 
					//echo "TEST sur " . $filename . "<br>";
					$largeur = $size[0];
					$hauteur = $size[1];
					
					if ($hauteur > $hauteur_maxi) {
						//echo " Il faut retailler !!!<br>";
						$fichier_a_retailler = $filename;
					}
					
					//echo "1 largeur : " . $largeur . "<br>";
					//echo "1 hauteur : " . $hauteur . "<br>";
				}
				
				// Redimensionnement de l'image ET création d'une vignette
				if ( $erreur == 0 && ($hauteur > $hauteur_maxi)) {
					
					//echo "fichier a retailler : " . $fichier_a_retailler . "<br>";
					$i = new ImageManipulator($fichier_a_retailler);
					
					$nouvelle_hauteur  = $hauteur_maxi;
					$nouvelle_largeur = round(($nouvelle_hauteur * $largeur) / $hauteur) ;
					
					$i->resample($nouvelle_largeur, $nouvelle_hauteur);
					$filename2 = $rep_destination . $nom_fichier;
					//echo "--> " . $filename . "<br>";
					$i->save_jpeg($filename2);
					$i->end();
					
					//$autre_chemin = "../../cartfile/im/produit";
					//copy($rep_destination . $nom_fichier, $autre_chemin . "/" . $nom_fichier);
					
					$size = GetImageSize($filename2);
					//echo "TEST sur " . $filename . "<br>";
					$largeur = $size[0];
					$hauteur = $size[1];
					
					//echo "2 largeur : " . $largeur . "<br>";
					//echo "2 hauteur : " . $hauteur . "<br>";
				}
				
				// On retourne le nom du fichier
				return $nom_fichier;
			}
			else {
				$GLOBALS["erreur"] = "Impossible de copier le fichier : " . $resultat;
				return false;
			}
		}
		else {
			$GLOBALS["erreur"] = "Le type du fichier choisi est incorrect.";
			return false;
		}
	}
示例#24
0
 private function resample(&$img, ImageManipulator $source, $owdt, $ohgt, $maxwdt, $maxhgt, $quality = 1)
 {
     // make sure the image doesn't get enlarged
     $maxwdt = min($maxwdt, $owdt);
     $maxhgt = min($maxhgt, $ohgt);
     if (!$maxwdt) {
         $divwdt = 1;
     } else {
         $divwdt = max(1, $owdt / $maxwdt);
     }
     if (!$maxhgt) {
         $divhgt = 1;
     } else {
         $divhgt = max(1, $ohgt / $maxhgt);
     }
     if ($divwdt >= $divhgt) {
         $newwdt = round($owdt / $divwdt);
         $newhgt = round($ohgt / $divwdt);
     } else {
         $newhgt = round($ohgt / $divhgt);
         $newwdt = round($owdt / $divhgt);
     }
     // return same image if resizing is not necessary
     if ($newwdt == $owdt && $newhgt == $ohgt) {
         return false;
     }
     $tn = imagecreatetruecolor($newwdt, $newhgt);
     if (in_array($source->getType(), array(IMAGETYPE_GIF, IMAGETYPE_PNG))) {
         $trnprt_indx = imagecolortransparent($img);
         // If we have a specific transparent color
         if ($trnprt_indx >= 0) {
             // Get the original image's transparent color's RGB values
             $trnprt_color = imagecolorsforindex($img, $trnprt_indx);
             // Allocate the same color in the new image resource
             $trnprt_indx = imagecolorallocate($tn, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
             // Completely fill the background of the new image with allocated color.
             imagefill($tn, 0, 0, $trnprt_indx);
             // Set the background color for new image to transparent
             imagecolortransparent($tn, $trnprt_indx);
         } elseif ($source->getType() == IMAGETYPE_PNG) {
             // Turn off transparency blending (temporarily)
             imagealphablending($tn, false);
             // Create a new transparent color for image
             $color = imagecolorallocatealpha($tn, 0, 0, 0, 127);
             // Completely fill the background of the new image with allocated color.
             imagefill($tn, 0, 0, $color);
             // Restore transparency blending
             imagesavealpha($tn, true);
         }
     }
     if ($quality) {
         imagecopyresampled($tn, $img, 0, 0, 0, 0, $newwdt, $newhgt, $owdt, $ohgt);
     } else {
         imagecopyresized($tn, $img, 0, 0, 0, 0, $newwdt, $newhgt, $owdt, $ohgt);
     }
     imagedestroy($img);
     $img = $tn;
     return array($newwdt, $newhgt);
 }
示例#25
0
 $licensetypeid6 = mysqli_real_escape_string($db, $_POST["licensetypeid6"]);
 $licensetypeid6 = encrypt($licensetypeid6, "");
 $licenseissuedateid6 = mysqli_real_escape_string($db, $_POST["licenseissuedateid6"]);
 $licenseissuedateid6 = encrypt($licenseissuedateid6, "");
 $licenseexpirationdateid6 = mysqli_real_escape_string($db, $_POST["licenseexpirationdateid6"]);
 $licenseexpirationdateid6 = encrypt($licenseexpirationdateid6, "");
 $licensetermid6 = mysqli_real_escape_string($db, $_POST["licensetermid6"]);
 $licensetermid6 = encrypt($licensetermid6, "");
 //Process New Profile Picture
 if ($_FILES['picture']['name']) {
     require_once "ImageManipulator.php";
     $validExtensions = array('.jpg', '.JPG', '.jpeg', '.JPEG', '.gif', '.GIF', '.png', '.PNG');
     $fileExtension = strrchr($_FILES['picture']['name'], ".");
     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 {
            //  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>";
            //    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);
示例#27
0
 /**
  * Builds an image upload form validator
  *
  * @return RequestValidator
  */
 protected function buildValidator($catId)
 {
     $validator = $this->getValidator($this->getModelClass() . "_" . $catId, $this->request);
     $uploadCheck = new IsFileUploadedCheck($this->translate(!empty($_FILES['image']['name']) ? '_err_too_large' : '_err_not_uploaded'));
     $uploadCheck->setFieldName('image');
     $validator->addCheck('image', $uploadCheck);
     $manip = new ImageManipulator();
     $imageCheck = new IsImageUploadedCheck($this->translate('_err_not_image'));
     $imageCheck->setFieldName('image');
     $imageCheck->setValidTypes($manip->getValidTypes());
     $validator->addCheck('image', $imageCheck);
     return $validator;
 }
示例#28
0
require_once 'db.php';
require_once 'imageManipulator.php';
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);
示例#29
0
<?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';
}
        $stmt = $dbh->prepare($sql);
        $stmt->execute();
        $notice .= "password berhasil di rubah" . "<br/>";
    } else {
        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);