当前位置: 首页>>代码示例>>PHP>>正文


PHP exif_imagetype函数代码示例

本文整理汇总了PHP中exif_imagetype函数的典型用法代码示例。如果您正苦于以下问题:PHP exif_imagetype函数的具体用法?PHP exif_imagetype怎么用?PHP exif_imagetype使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了exif_imagetype函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upload

 /**
  * Upload an image.
  *
  * @param $file
  * @return array
  */
 public function upload(array $file)
 {
     if (!$file) {
         $status = ['status' => 'error', 'message' => GENERIC_UPLOAD_ERROR_MESSAGE];
         return $status;
     }
     $tempName = $file['tmp_name'];
     if (is_null($tempName)) {
         $status = ['status' => 'error', 'message' => GENERIC_UPLOAD_ERROR_MESSAGE];
         return $status;
     }
     $imageInfo = getimagesize($tempName);
     if (!$imageInfo) {
         $status = ['status' => 'error', 'message' => 'Only images are allowed'];
         return $status;
     }
     $fileType = image_type_to_mime_type(exif_imagetype($tempName));
     if (!in_array($fileType, $this->_allowedTypes)) {
         $status = ['status' => 'error', 'message' => 'File type not allowed'];
         return $status;
     }
     $fileName = htmlentities($file['name']);
     $height = $this->_imagick->getImageHeight();
     $width = $this->_imagick->getImageWidth();
     $uploadPath = $_SERVER['DOCUMENT_ROOT'] . PROPERTY_IMG_TMP_DIR;
     if (!move_uploaded_file($tempName, $uploadPath . "/{$fileName}")) {
         $status = ['status' => 'error', 'message' => 'Can\'t move file'];
         return $status;
     }
     $status = ['status' => 'success', 'url' => PROPERTY_IMG_TMP_DIR . '/' . $fileName, 'width' => $width, 'height' => $height, 'token' => $_SESSION['csrf_token']];
     return $status;
 }
开发者ID:justincdotme,项目名称:bookme,代码行数:38,代码来源:ImageUpload.php

示例2: yukle

function yukle($hedef = NULL, $alan = 'file')
{
    $yuklenen = F3::get("FILES.{$alan}.tmp_name");
    // hedef ve yüklenen dosyanın boş olmasına izin veriyoruz
    // herhangi biri boşsa mesele yok, çağırana dön
    if (empty($hedef) || empty($yuklenen)) {
        return true;
    }
    // bu bir uploaded dosya olmalı, fake dosyalara izin yok
    if (is_uploaded_file($yuklenen)) {
        // boyutu sınırla, değeri öylesine seçtim
        if (filesize($yuklenen) > 600000) {
            F3::set('error', 'Resim çok büyük');
        } else {
            if (exif_imagetype($yuklenen) != IMAGETYPE_JPEG) {
                F3::set('error', 'Resim JPEG değil');
            } else {
                if (file_exists($hedef)) {
                    F3::set('error', 'Resim zaten kaydedilmiş');
                } else {
                    if (!move_uploaded_file($yuklenen, $hedef)) {
                        F3::set('error', 'Dosya yükleme hatası');
                    }
                }
            }
        }
        // yok başka bir ihtimal!
    } else {
        // bu aslında bir atak işareti
        F3::set('error', 'Dosya geçerli bir yükleme değil');
    }
    return false;
}
开发者ID:seyyah,项目名称:uzkay,代码行数:33,代码来源:kaydet.php

示例3: setFile

 private function setFile($file)
 {
     $errorCode = $file['error'];
     if ($errorCode === UPLOAD_ERR_OK) {
         $type = exif_imagetype($file['tmp_name']);
         if ($type) {
             $extension = image_type_to_extension($type);
             $src = 'img/' . date('YmdHis') . '.original' . $extension;
             if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) {
                 if (file_exists($src)) {
                     unlink($src);
                 }
                 $result = move_uploaded_file($file['tmp_name'], $src);
                 if ($result) {
                     $this->src = $src;
                     $this->type = $type;
                     $this->extension = $extension;
                     $this->setDst();
                 } else {
                     $this->msg = 'Failed to save file';
                 }
             } else {
                 $this->msg = 'Please upload image with the following types: JPG, PNG, GIF';
             }
         } else {
             $this->msg = 'Please upload image file';
         }
     } else {
         $this->msg = $this->codeToMessage($errorCode);
     }
 }
开发者ID:vfssantos,项目名称:belle_server,代码行数:31,代码来源:crop.php

示例4: convert

 public function convert($source = '')
 {
     if (!empty($source)) {
         $this->source = $source;
     }
     if (empty($this->source) || !file_exists($this->source)) {
         $this->error(1, 'The source file "' . $this->source . '" is missing');
         return false;
     }
     switch (exif_imagetype($this->source)) {
         case IMAGETYPE_GIF:
             $result = $this->_convertImage($this->source, 'gif');
             break;
         case IMAGETYPE_JPEG:
             $result = $this->_convertImage($this->source, 'jpg');
             break;
         case IMAGETYPE_PNG:
             $result = $this->_convertImage($this->source, 'png');
             break;
         case IMAGETYPE_BMP:
             $result = $this->image = file_get_contents($this->source);
             break;
         default:
             $this->error(2, 'Unsupported file type');
             return false;
     }
     return $result;
 }
开发者ID:askzap,项目名称:ultimate,代码行数:28,代码来源:class.convert_to_bmp.php

示例5: filter

 public function filter($value)
 {
     $img_orig = $this->_createImage($value);
     $img_new = $this->_grayscaleImage($img_orig);
     $this->_outputImage($img_new, exif_imagetype($value), $value);
     return $value;
 }
开发者ID:hexdoll,项目名称:Image-Filter,代码行数:7,代码来源:Grayscale.php

示例6: __construct

 /**
  * 构造函数
  * @param array $files 要处理的图片列表
  */
 public function __construct(array $files = array())
 {
     //名称生成方式
     $this->namecall = function ($name) {
         return 'Other/' . $name . '-' . md5($name);
     };
     //设置文件信息
     foreach ($files as $key => $file) {
         //对文件名中的空格做处理
         $filename = str_replace(' ', '%20', $file);
         //取得文件的大小信息
         if (false !== ($this->infos[$file] = getimagesize($filename))) {
             //取得扩展名
             //支持格式 see http://www.php.net/manual/zh/function.exif-imagetype.php
             $this->infos[$file]['ext'] = image_type_to_extension(exif_imagetype($filename), 0);
             //如果不在允许的图片类型范围内
             if (!in_array($this->infos[$file]['ext'], $this->exts)) {
                 unset($this->infos[$file]);
             }
         } else {
             //如果获取信息失败则取消设置
             unset($this->infos[$file]);
         }
     }
 }
开发者ID:lunnlew,项目名称:Norma_Code,代码行数:29,代码来源:LAEGDImage.php

示例7: fixImageOrientation

 function fixImageOrientation($path)
 {
     $info = getimagesize($path);
     if ($info['mime'] != "image/jpeg") {
         return;
     }
     $exif = exif_read_data($path);
     if (exif_imagetype($path) != IMAGETYPE_JPEG) {
         return;
     }
     if (empty($exif['Orientation'])) {
         return;
     }
     $image = imagecreatefromjpeg($path);
     switch ($exif['Orientation']) {
         case 3:
             $image = imagerotate($image, 180, 0);
             break;
         case 6:
             $image = imagerotate($image, -90, 0);
             break;
         case 8:
             $image = imagerotate($image, 90, 0);
             break;
     }
     imagejpeg($image, $path);
 }
开发者ID:krombox,项目名称:motion,代码行数:27,代码来源:ImageTypeExtension.php

示例8: post

 protected function post()
 {
     $json = array();
     $userName = $this->user->getUserName();
     $tmpFileName = $this->request->files['file']['tmp_name'];
     $srcFileName = urldecode($this->request->files['file']['name']);
     $tmpfilesize = filesize($this->request->files['file']['tmp_name']);
     $vendorId = $this->user->getVP();
     //file type must be acceptable
     $imageType = exif_imagetype($this->request->files['file']['tmp_name']);
     if (IMAGETYPE_GIF != $imageType && IMAGETYPE_JPEG != $imageType && IMAGETYPE_PNG != $imageType) {
         throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_FILE_ERROR, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_FILE_ERROR));
     }
     //file size must be >0
     if (0 >= $tmpfilesize) {
         throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_FILE_ERROR, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_FILE_ERROR));
     }
     //append timestamp to all uploaded image filenames to ensure uniqueness
     $path_parts = pathinfo($srcFileName);
     $fileNameTimestamped = $path_parts['filename'] . "_" . time() . "." . $path_parts['extension'];
     $destination = "catalog/" . $userName . "/" . $fileNameTimestamped;
     //move tmpfile to proper vendor-specific location
     if (!rename($tmpFileName, DIR_IMAGE . $destination)) {
         throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_FILE_ERROR, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_FILE_ERROR));
     }
     $this->load->model('catalog/vdi_vendor_profile');
     //ask model to associate image in db, providing vendor id and destination filename
     $this->model_catalog_vdi_vendor_profile->setVendorProfileImage($vendorId, $destination);
     $json['filename'] = $fileNameTimestamped;
     $this->response->setOutput($json);
 }
开发者ID:projectwife,项目名称:tesitoo-opencart,代码行数:31,代码来源:profile_image.php

示例9: type

 /**
  * get the imagetype of an image object
  * @return string imagetype XXX constant
  */
 public function type()
 {
     if ($this->exists() == false) {
         return "Unable to get file";
     }
     return exif_imagetype($this->url);
 }
开发者ID:idoqo,项目名称:yedoe,代码行数:11,代码来源:image.class.php

示例10: uploadRemoteFile

 function uploadRemoteFile($urlimage, $filename, $urlslug, $user_id = NULL)
 {
     $this->CI->output->set_header('Content-Type: application/json; charset=utf-8');
     $user_name = isset($user_id) ? username($user_id) : $this->CI->ion_auth->user()->row()->username;
     //get file info so we can check for allowed extensions
     $file_parts = pathinfo($urlimage);
     $exts = array('jpg', 'gif', 'png', 'jpeg');
     if (isset($file_parts['extension']) && in_array($file_parts['extension'], $exts)) {
         //check the exif data to ensure its a valid image type
         $image_exists = @fopen($urlimage, "r");
         if ($image_exists === false) {
             $output_array = array('validation' => 'error', 'response' => 'error', 'message' => 'Check image URL. Supplied URL does not appear to be an image.');
             $this->CI->output->set_output(json_encode($output_array));
         } else {
             fclose($image_exists);
             if (exif_imagetype($urlimage)) {
                 //send back json error for modal
                 //if folder for song does not  exist, make the folder
                 if (!file_exists(FCPATH . 'asset_uploads/' . $user_name . '/' . $urlslug)) {
                     mkdir(FCPATH . 'asset_uploads/' . $user_name . '/' . $urlslug, 0755, true);
                     file_put_contents(FCPATH . 'asset_uploads/' . $user_name . '/' . $urlslug . '/index.html', 'index.html');
                 }
                 //get the image
                 $image = file_get_contents($urlimage);
                 //save the image
                 file_put_contents(FCPATH . 'asset_uploads/' . $user_name . '/' . $urlslug . '/' . $filename . '.' . $file_parts['extension'], $image);
                 return true;
             }
         }
     } else {
         //send back json error for modal
         $output_array = array('validation' => 'error', 'response' => 'error', 'message' => 'Image filetype not supported. JPG or PNG only please!');
         $this->CI->output->set_output(json_encode($output_array));
     }
 }
开发者ID:JamesWuChina,项目名称:hhvip-ci,代码行数:35,代码来源:Images.php

示例11: getImageFromUrl

 public static function getImageFromUrl($image_url)
 {
     try {
         $mime = image_type_to_mime_type(exif_imagetype($image_url));
     } catch (Exception $e) {
         throw new MimeTypeException($e->getMessage());
     }
     //Get image based on mime and set to $im
     switch ($mime) {
         case 'image/jpeg':
             $im = imagecreatefromjpeg($image_url);
             break;
         case 'image/gif':
             $im = imagecreatefromgif($image_url);
             break;
         case 'image/png':
             $im = imagecreatefrompng($image_url);
             break;
         case 'image/wbmp':
             $im = imagecreatefromwbmp($image_url);
             break;
         default:
             throw new MimeTypeException("An image of '{$mime}' mime type is not supported.");
             break;
     }
     return $im;
 }
开发者ID:aaronbullard,项目名称:litmus,代码行数:27,代码来源:LitmusService.php

示例12: save_image

function save_image($image_file, $user_id)
{
    global $image_dir;
    if (!file_exists($image_dir . $user_id)) {
        if (mkdir($image_dir . $user_id, 0777)) {
            chmod($image_dir . $user_id, 0777);
        } else {
            echo json_encode(array("error" => "could not create user directory "));
        }
    }
    if (!isset($image_file["tmp_name"])) {
        echo json_encode(array("error" => "file not selected"));
        exit;
    } else {
        $file_path = $image_dir . $user_id . "/" . md5(uniqid(rand(), true)) . ".png";
        $temp_file = $image_file["tmp_name"];
        $save = false;
        $type = exif_imagetype($temp_file);
        if ($type == IMAGETYPE_PNG) {
            $save = move_uploaded_file($temp_file, $file_path);
        }
        if ($type == IMAGETYPE_JPEG || $type == IMAGETYPE_GIF) {
            $save = imagepng(imagecreatefromstring(file_get_contents($temp_file)), $file_path);
        }
        if (!$save) {
            echo json_encode(array("error" => "upload faild"));
            exit;
        }
    }
    return $file_path;
}
开发者ID:IshitaTakeshi,项目名称:ClothingRecommenderWeb,代码行数:31,代码来源:libs.php

示例13: uploadSlide

 function uploadSlide($file)
 {
     if (!empty($file['tmp_name'])) {
         if (is_uploaded_file($file['tmp_name'])) {
             //verify its actually an image
             if (exif_imagetype($file['tmp_name'])) {
                 $saved = move_uploaded_file($file['tmp_name'], $this->slides_fp . $file['name']);
                 if ($saved) {
                     $returndata = array();
                     $returndata['title'] = $file['name'];
                     $returndata['image'] = '/' . $this->slides_dir . $file['name'];
                     $returndata['description'] = '';
                     $returndata['link'] = '';
                     return $returndata;
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
开发者ID:ngardner,项目名称:BentoCMS,代码行数:27,代码来源:SlideshowModel.php

示例14: insertNewImage

 function insertNewImage($FilePath, $OriginalFileName)
 {
     $ImageType = exif_imagetype($FilePath);
     $Email = $this->Email;
     $this->initializeConnection();
     $sql = "INSERT INTO UserFiles(ImageType,FileName,Owner) OUTPUT INSERTED.FileID VALUES (?,?,?)";
     $params = array($ImageType, $OriginalFileName, $Email);
     global $conn;
     if ($conn) {
         $stmt = sqlsrv_query($conn, $sql, $params);
         if ($stmt === false) {
             $error = sqlsrv_errors();
             return false;
         } else {
             if (sqlsrv_has_rows($stmt) > 0) {
                 $FileID = '';
                 while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
                     $FileID = $row['FileID'];
                 }
                 return $this->uploadImage($FilePath, $FileID);
             } else {
                 return false;
             }
         }
     }
 }
开发者ID:GPHofficial,项目名称:urimg,代码行数:26,代码来源:fileManagement.php

示例15: get_file_info

 private function get_file_info($file)
 {
     $filesize = 0;
     $fileParts = parse_url($file);
     $path = arr::get($fileParts, 'path');
     $path = substr_replace($path, '', 0, 1);
     $path = urldecode($path);
     $pathParts = explode('/', $path);
     $name = end($pathParts);
     if (is_file(PUBLIC_ROOT . $path)) {
         $filesize = filesize(PUBLIC_ROOT . $path) / 1000;
     }
     $mbSize = $filesize / 1000;
     $type = 'KB';
     if ($mbSize > 1) {
         $filesize = $mbSize;
         $type = 'MB';
     }
     $fileType = 'file';
     try {
         $exifImageType = @exif_imagetype(PUBLIC_ROOT . $path);
         if ($exifImageType > 0 && $exifImageType < 18) {
             $fileType = 'image';
         }
     } catch (Exception $e) {
     }
     return array('type' => $type, 'size' => round($filesize, 2, PHP_ROUND_HALF_UP), 'name' => $name, 'file_type' => $fileType);
 }
开发者ID:ariol,项目名称:adminshop,代码行数:28,代码来源:Abstract.php


注:本文中的exif_imagetype函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。