Beispiel #1
1
 /**
  * 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;
 }
Beispiel #2
0
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;
}
Beispiel #3
0
 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);
     }
 }
 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;
 }
Beispiel #5
0
 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;
 }
Beispiel #6
0
 /**
  * 构造函数
  * @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]);
         }
     }
 }
Beispiel #7
0
 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);
 }
 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);
 }
Beispiel #9
0
 /**
  * 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);
 }
Beispiel #10
0
 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));
     }
 }
Beispiel #11
0
 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;
 }
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;
}
Beispiel #13
0
 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;
     }
 }
Beispiel #14
0
 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;
             }
         }
     }
 }
Beispiel #15
0
 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);
 }
function isImage($tmp_name)
{
    $allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
    $detectedType = exif_imagetype($tmp_name);
    $rs = in_array($detectedType, $allowedTypes);
    return $rs;
}
Beispiel #17
0
 /**
  *  Resize an image to the specified dimensions, placing the resulting
  *  image in the specified location.  At least one of $newWidth or
  *  $newHeight must be specified.
  *
  *  @param  string  $type       Either 'thumb' or 'disp'
  *  @param  integer $newWidth   New width, in pixels
  *  @param  integer $newHeight  New height, in pixels
  *  @return string  Blank if successful, error message otherwise.
  */
 public static function ReSize($src, $dst, $newWidth = 0, $newHeight = 0)
 {
     global $_LGLIB_CONF;
     // Calculate the new dimensions
     $A = self::reDim($src, $newWidth, $newHeight);
     if ($A === false) {
         COM_errorLog("Invalid image {$src}");
         return 'invalid image conversion';
     }
     list($sWidth, $sHeight, $dWidth, $dHeight) = $A;
     // Get the mime type for the glFusion resizing functions
     $mime_type = image_type_to_mime_type(exif_imagetype($src));
     // Returns an array, with [0] either true/false and [1]
     // containing a message.
     $result = array();
     if (function_exists(_img_resizeImage)) {
         $result = _img_resizeImage($src, $dst, $sHeight, $sWidth, $dHeight, $dWidth, $mime_type);
     } else {
         $result[0] = false;
     }
     if ($result[0] == true) {
         return '';
     } else {
         COM_errorLog("Failed to convert {$src} ({$sHeight} x {$sWidth}) to {$dst} ({$dHeight} x {$dWidth})");
         return 'invalid image conversion';
     }
 }
Beispiel #18
0
 public static function supports($path)
 {
     if (!extension_loaded('exif')) {
         throw new Exception("Cannot verify '{$path}' image type, Exif extension is not loaded");
     }
     return exif_imagetype($path) == IMAGETYPE_GIF;
 }
 public function savePhoto()
 {
     $input = \Request::all();
     $data = explode(',', $input['image_base64']);
     $filename = $input['filename'];
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     $ext_extra_data = parse_url($ext, PHP_URL_QUERY);
     $ext = str_replace("?" . $ext_extra_data, "", $ext);
     $filename = uniqid() . "." . $ext;
     $ifp = fopen($this->save_photo_path . "/" . $filename, "wb");
     fwrite($ifp, base64_decode($data[1]));
     fclose($ifp);
     $type = exif_imagetype($this->save_photo_path . "/" . $filename);
     if (!in_array($type, $this->allow_image_types)) {
         return response(['error' => 'not_allowed'], 412);
     }
     // deactivate other photos
     $affected = UserPhoto::where('status', '=', 1)->where('user_id', \Auth::user()->id)->update(array('status' => 0));
     $userPhoto = new UserPhoto();
     $userPhoto->user_id = \Auth::user()->id;
     $userPhoto->filename = $filename;
     $userPhoto->save();
     $userPhoto->path = url("/" . $this->save_photo_folder . "/" . $userPhoto->filename);
     return $userPhoto;
 }
Beispiel #20
0
 public static function getThumbnail($url, $size = 25)
 {
     $fileName = self::getImageName($url);
     if (!empty($url)) {
         if (exif_imagetype($url) != IMAGETYPE_JPEG) {
             list($widthOrig, $heightOrig) = getimagesize($url);
             if ($heightOrig > 840) {
                 $width = ceil($widthOrig * $size / 100);
                 $height = ceil($heightOrig * $size / 100);
                 // This resamples the image
                 $imageR = \imagecreatetruecolor($width, $height);
                 $image = \imagecreatefromjpeg($url);
                 \imagecopyresampled($imageR, $image, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
                 $destinationPath = __DIR__ . self::PATH . $fileName;
                 if (!file_exists($destinationPath)) {
                     imagejpeg($imageR, $destinationPath);
                 }
                 return self::PATH_TO_HERE . self::PATH . $fileName;
             } else {
                 return $url;
             }
         } else {
             return $url;
         }
     } else {
         return $url;
     }
 }
Beispiel #21
0
 /**
  * добавляет штам к изображению
  * @param string $image путь до изображения
  * @param bool $flag =false удалять изображение до подписи
  * @return int|string путь до нового файла
  * @throws \yii\base\Exception
  */
 public function setStamp($image, $flag = false)
 {
     if (file_exists($image)) {
         $type = exif_imagetype($image);
         if ($type == IMAGETYPE_JPEG) {
             $img = imagecreatefromjpeg($image);
         } else {
             if ($type == IMAGETYPE_PNG) {
                 $img = imagecreatefrompng($image);
             } else {
                 throw new Exception('Invalid type of file');
             }
         }
         $sx = imagesx($this->stamp);
         $sy = imagesy($this->stamp);
         $this->translatePosition(imagesx($img), imagesy($img), $sx, $sy);
         imagecopy($img, $this->stamp, imagesx($img) - $sx - $this->posX, imagesy($img) - $sy - $this->posY, 0, 0, imagesx($this->stamp), imagesy($this->stamp));
         $filename = dirname($image) . '/' . time();
         if ($type == IMAGETYPE_JPEG) {
             $filename .= '.jpg';
             imagejpeg($img, $filename);
         } else {
             $filename .= '.png';
             imagepng($img, $filename);
         }
         imagedestroy($img);
         if ($flag) {
             unlink($image);
         }
         return $filename;
     } else {
         throw new Exception('File not found');
     }
 }
 function __construct($file)
 {
     $this->filename = $file;
     $this->file_res = __ROOT__ . "/shopimagepreview/" . $this->filename;
     //         print $this->file_res;
     $filename11 = __ROOT__ . "/shopimage/" . $file;
     list($width, $height) = getimagesize($filename11);
     //gпроанализируем соотношения сторон и сожмем
     $dif = $width / $height;
     if ($width > $height) {
         $new_width = 230;
         $new_height = $new_width / $dif;
     } else {
         $new_height = 170;
         $new_width = $new_width * $dif;
     }
     $new_width = $new_height * $dif;
     $image_p = imagecreatetruecolor($new_width, $new_height);
     $col2 = imagecolorallocate($image_p, 255, 255, 255);
     imagefilledrectangle($image_p, 0, 0, $new_width, $new_width, $col2);
     //проверка на мимтипы
     if (exif_imagetype($filename11) == 2) {
         $image = imagecreatefromjpeg($filename11);
         imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
         imagejpeg($image_p, $this->file_res, 90);
     } elseif (exif_imagetype($filename11) == 3) {
         //     echo "ALARM!!! ETHO PNG!!!!".$filename11;
         $image = imagecreatefrompng($filename11);
         imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
         imagepng($image_p, $this->file_res, 5);
     }
 }
Beispiel #23
0
 private function setFile($file, $file_name)
 {
     $errorCode = $file['error'];
     if ($errorCode === UPLOAD_ERR_OK) {
         $type = exif_imagetype($file['tmp_name']);
         if ($type) {
             $extension = image_type_to_extension($type);
             $src = 'img/' . $file_name . '.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($file_name);
                 } else {
                     $this->msg = '上传图片失败';
                 }
             } else {
                 $this->msg = '请上传支持的格式,包括JPG, PNG, GIF';
             }
         } else {
             $this->msg = '请上传有效的图片';
         }
     } else {
         $this->msg = $this->codeToMessage($errorCode);
     }
 }
Beispiel #24
0
function getData($f, $nomd5 = false)
{
    $ext = '';
    $res = '';
    $Type = 0;
    $Md5 = '';
    $size = 0;
    if (!$nomd5) {
        $Md5 = md5_file($f);
    } else {
        $Md5 = "";
    }
    $Type = @exif_imagetype($f);
    switch ($Type) {
        case 1:
            $ext = "gif";
            break;
        case 2:
            $ext = "jpg";
            break;
        case 3:
            $ext = "png";
            break;
    }
    $size = filesize($f);
    list($w, $h, $t, $a) = getimagesize($f);
    $res = $w . 'x' . $h;
    return array("ext" => $ext, "res" => $res, "type" => $Type, "md5" => $Md5, "size" => $size);
}
Beispiel #25
0
 protected function getImage($image_url)
 {
     $this->url = $image_url;
     $mime = image_type_to_mime_type(exif_imagetype($image_url));
     $im;
     //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:
             return NULL;
             break;
     }
     $this->image = $im;
     return $this;
 }
 function fileupload_trigger_check()
 {
     if (intval(get_query_var('postform_fileupload')) == 1) {
         if (!(get_option('bbp_5o1_toolbar_allow_image_uploads') && (is_user_logged_in() || get_option('bbp_5o1_toolbar_allow_anonymous_image_uploads')))) {
             echo htmlspecialchars(json_encode(array("error" => __("You are not permitted to upload images.", 'bbp_5o1_toolbar'))), ENT_NOQUOTES);
             exit;
         }
         require_once dirname(__FILE__) . '/includes/fileuploader.php';
         // list of valid extensions, ex. array("jpeg", "xml", "bmp")
         $allowedExtensions = array('jpg', 'jpeg', 'png', 'gif');
         // Because using Extensions only is very bad.
         $allowedMimes = array(IMAGETYPE_JPEG, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF);
         // max file size in bytes
         $sizeLimit = bbp_5o1_images_panel::return_bytes(min(array(ini_get('post_max_size'), ini_get('upload_max_filesize'))));
         $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
         $directory = wp_upload_dir();
         $result = $uploader->handleUpload(trailingslashit($directory['path']));
         $mime = exif_imagetype($result['file']);
         if (!$mime || !in_array($mime, $allowedMimes)) {
             $deleted = unlink($result['file']);
             echo htmlspecialchars(json_encode(array("error" => __("Disallowed file type.", 'bbp_5o1_toolbar'))), ENT_NOQUOTES);
             exit;
         }
         // Construct the attachment array
         $attachment = array('post_mime_type' => $mime ? image_type_to_mime_type($mime) : '', 'guid' => trailingslashit($directory['url']) . $result['filename'], 'post_parent' => 0, 'post_title' => $result['name'], 'post_content' => 'Image uploaded for a forum topic or reply.');
         // Save the data
         $id = wp_insert_attachment($attachment, $result['file'], 0);
         $result['id'] = $id;
         $result['attachment'] = $attachment;
         $result = array("success" => true, "file" => $attachment['guid']);
         echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
         exit;
     }
 }
function subirImagen($file)
{
    $path = "../../imagenes/";
    $extension = "";
    $newName = "";
    $fullPath = "";
    $query = "";
    if ($file['error'] == 0) {
        if (is_uploaded_file($file['tmp_name'])) {
            $imagteType = exif_imagetype($file['tmp_name']);
            if ($imagteType == IMAGETYPE_JPEG) {
                $extension = ".jpeg";
                $newName = md5($file['name'] . date('d-m-Y H:i:s')) . $extension;
            } elseif ($imagteType == IMAGETYPE_PNG) {
                $extension = ".png";
                $newName = md5($file['name'] . date('d-m-Y H:i:s')) . $extension;
            }
            //Moviendo la imagen al directorio permanente
            if ($newName != "") {
                if (move_uploaded_file($file['tmp_name'], $path . $newName)) {
                    $fullPath = $path . $newName;
                }
            }
        }
    }
    return $fullPath;
}
Beispiel #28
0
 public function frame()
 {
     $params = array();
     if (Request::hasFile('file')) {
         $file = Request::file('file');
         $name = $file->getClientOriginalName();
         $pathinfo = pathinfo($name);
         $uniqName = uniqid() . '.' . $pathinfo['extension'];
         $tmpDir = base_path() . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
         $webPath = '/upload/tmp/' . $uniqName;
         $fullPath = $tmpDir . $uniqName;
         $params['webPath'] = $webPath;
         $file->move($tmpDir, $uniqName);
         Session::set('upload', $webPath);
         if (!exif_imagetype($fullPath)) {
             $params['webPath'] = 'FAIL_IMAGE';
         } else {
             list($width, $height, $type, $attr) = getimagesize($fullPath);
             if ($width < 160 || $height < 160) {
                 $params['webPath'] = 'FAIL_SIZE';
             }
         }
     }
     return view('admin.form_frame', $params);
 }
Beispiel #29
0
 private function getType($path)
 {
     if (!function_exists('exif_imagetype')) {
         throw new Exception('Не подключено расширение exif_imagetype в php.ini');
     }
     return exif_imagetype($path);
 }
Beispiel #30
0
 /**
  * @param $prName
  * @param bool $prMultiple
  * @return array|bool|mixed
  */
 public static final function file($prName, $prMultiple = false)
 {
     if ($_FILES[$prName]['name'][0] == NULL) {
         return false;
     }
     $aItem = array();
     foreach (range(0, sizeof($_FILES[$prName]['name']) - 1) as $x) {
         foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $label) {
             $aItem[$x][$label] = is_array($_FILES[$prName][$label]) ? $_FILES[$prName][$label][$x] : $_FILES[$prName][$label];
         }
     }
     foreach ($aItem as $x => $aInfo) {
         /**
          * Get the extension of the file
          */
         $aItem[$x]['extension'] = mb_strtolower(pathinfo($aInfo['name'], PATHINFO_EXTENSION), 'UTF-8');
         /**
          * Convert the size
          */
         $size = $aInfo['size'];
         $aItem[$x]['size'] = array('byte' => number_format($size, 2, '.', ''), 'kilobyte' => number_format($size / 1024, 2, '.', ''), 'megabyte' => number_format($size / 1048576, 2, '.', ''), 'gigabyte' => number_format($size / 1073741824, 2, '.', ''));
         /** Se for uma imagem */
         if (exif_imagetype($aInfo['tmp_name']) !== false) {
             /** Recuper as dimensções */
             $aSize = getimagesize($aInfo['tmp_name']);
             if ($aSize) {
                 /** Incrementa o array com as dimensões */
                 $aItem[$x]['dimension'] = array('width' => $aSize[0], 'height' => $aSize[1]);
             }
         }
     }
     return sizeof($aItem) > 1 || $prMultiple ? $aItem : $aItem[0];
 }