日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php如何加密图片,php实现图片加密解密,支持设置密码 (两年后版本!)

發布時間:2025/3/8 php 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php如何加密图片,php实现图片加密解密,支持设置密码 (两年后版本!) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

* by hello

* 84587470

*

* php 文件加密類,支持設置密碼,圖片,文件都可以!情侶們的福音!!!

**/

$from = 'C:\Users\Administrator\Desktop\t\test.png';$to = 'C:\Users\Administrator\Desktop\t\\';//加密

encrpty::en($from , $to , 'xxxx');//解密

encrpty::de('C:\Users\Administrator\Desktop\t\00f8fbb037778e31455211b4bdcb0874' , $to , 'xxxx');classencrpty

{const DS =DIRECTORY_SEPARATOR;const FILE = 1;const DIRECTORY = 2;const ALL = 3;/**

* 文件加密

*

* @param $from 源

* @param $to 保存位置

* @param string $slat 密碼

*

* @return array*/

public static function en($from , $to , $slat = 'xxx')

{$data =['sign' => 1 ,

'msg' => '' ,];try{$imgObj = new \SplFileInfo($from);$stram = implode('' ,['@@_____' ,

$slat ,

'@@_____' ,

$imgObj->getBasename() ,

'@@_____' ,]). (file_get_contents($imgObj->getRealPath()));$stram = gzcompress($stram);file_put_contents(static::replaceToSysSeparator($to) . md5($imgObj->getRealPath()) , ($stram));

}catch (\Exception $exception)

{$data['sign'] = 0;$data['data'] = $exception->getMessage();

}return $data;

}/**

* 解密

*

* @param $from 源

* @param $to 保存位置

* @param string $slat 密碼

*

* @return array*/

public static function de($from , $to , $slat = 'xxx')

{$data =['sign' => 1 ,

'msg' => '' ,];try{$imgObj = new \SplFileInfo($from);$stram = file_get_contents($imgObj->getRealPath());$stram = gzuncompress($stram);$reg = implode('' ,['#' ,

'^@@_____' ,

preg_quote($slat , '#') ,

'@@_____' ,

'(.*?)' ,

'@@_____' ,

'#i' ,]);preg_match($reg , $stram , $res);if(isset($res[1]))

{

self::mkdir_($to);$result = preg_replace($reg , '' , $stram);file_put_contents(static::endDS($to) . $res[1] , $result);

}else{$data['sign'] = 0;$data['data'] = '解密出錯';

}

}catch (\Exception $exception)

{$data['sign'] = 0;$data['data'] = $exception->getMessage();

}return $data;

}/**

* 自動為路徑后面加DIRECTORY_SEPARATORY

*

* @param string $path 文件夾路徑

*

* @return string*/

public static function endDS($path)

{return rtrim(rtrim(static::replaceToSysSeparator($path) , '/') , '\\') . static::DS;

}/**

* @param $path

*

* @return string*/

public static function replaceToSysSeparator($path)

{return strtr($path ,['\\' => static::DS ,

'/' => static::DS ,]);

}/**

* @param $path

*

* @return string*/

public static function replaceToUrlSeparator($path)

{return strtr($path ,['\\' => '/' ,]);

}/**

* 格式化字節大小

*

* @param number $size 字節數

* @param string |int $de

*

* @return string 格式化后的帶單位的大小*/

public static function byteFormat($size , $de = 2)

{$a = array("B" ,

"KB" ,

"MB" ,

"GB" ,

"TB" ,

"PB" ,);$pos = 0;while ($size >= 1024)

{$size /= 1024;$pos++;

}return round($size , $de) . " " . $a[$pos];

}/**

* 創建文件夾

*

* @param $path

* @param int $mode

*

* @return bool*/

public static function mkdir_($path , $mode = 0777)

{return !is_dir(($path)) ? mkdir(($path) , $mode , 1) : @chmod($path , $mode);

}/**

* 列出文件夾里文件信息

*

* @param $path

* @param callable|null $callback

* @param int $flag

*

* @return array*/

public static function listDir($path , callable $callback = null , $flag = self::ALL)

{$files =[];if(is_dir($path) && is_readable($path))

{try{$directory = new \FilesystemIterator ($path);$filter = new \CallbackFilterIterator ($directory , function($current , $key , $iterator) use ($flag) {switch ($flag)

{case static::FILE:

return $current->isFile();case static::DIRECTORY:

return $current->isDir();default:

return true;

}

});foreach ($filter as $info)

{if(is_callable($callback))

{$files[] = call_user_func_array($callback ,[$info ,]);

}else{$files[] = $info;

}

}

}catch (\Exception $e)

{$files =[];

}

}return $files;

}

}

總結

以上是生活随笔為你收集整理的php如何加密图片,php实现图片加密解密,支持设置密码 (两年后版本!)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。