この画像アップロードソースコードは、画像をアップロードすることができ、サムネイルを生成し、アップロードされた画像に透かしを追加する機能も備えており、完璧な画像アップローダーと言えます。
phpチュートリアル画像アップロードコード(サムネイル生成とウォーターマーク追加機能付き)
この画像アップロードソースコードは画像をアップロードできるだけでなく、アップロードした画像にサムネイルを生成したりウォーターマークを追加したりする機能も備えており、完璧な画像アップロードクラスと言えます。
クラスアップファイル{
public $filepath = "www.bKjia.c0m/" //ファイル保存フォルダーをアップロードしますpublic $filesize = 1000000 //アップロードサイズを許可します
;//アップロードを許可するファイルの種類を変更したい場合は、[ switch ($upfiletype) { //ファイル タイプ ]を検索してください
public $reimagesize = array (
public $india = true //透かしを入れるかどうか、true の場合は false、いいえ
true, //サムネイルを生成するかどうか
400, //サムネイルの幅
300,//サムネイルの高さ
"" //サムネイル保存フォルダー。空の場合、サムネイルを生成する現在のファイルと同じディレクトリにあります。ファイルのプレフィックスは r_
です。 ); //サムネイル配列を生成するかどうか (生成するかどうか、サムネイルの幅、サムネイルの高さ、保存フォルダー); 注: 保存フォルダーの後には '/' が付きます。public $indiaimage = ""; //ウォーターマーク画像アドレスが空の場合、画像ウォーターマークは印刷されません。テキストウォーターマークがある場合は、画像ウォーターマークを有効にしないことをお勧めします。
public $indiaimagex = 100; //画像と画像の左側の間の距離
;public $indiaimagey = 10; // 画像と画像の上部の間の距離
;public $indiatext = "www.bKjia.c0m" //透かしテキスト
;public $fontsize = 6 //透かしのテキスト サイズ、最小 1、最大 6
public $indiatextx = 10; // テキストと画像の左側の間の距離
;public $indiatexty = 10; //テキストと画像の上部の間の距離
public $r = 250 //画像の色の三原色 $r 赤
;public $g = 250 //$g 緑
;パブリック $b = 250 //$b 青
;public $indiapath = ""; //透かし入りの画像の保存パス。空の場合は、元の画像を直接置き換えます
//开始上传处理
関数アップロードファイル($upfile) {
if ($upfile == "") {
die("uploadfile:パラメータ不足");
}
if (!file_exists($this->ファイルパス)) {
mkdir($this->ファイルパス);
}
$upfiletype = $upfile['type'];
$upfilesize = $upfile['size'];
$upfiletmpname = $upfile['tmp_name'];
$upfilename = $upfile['name'];
$upfileerror = $upfile['error'];
if ($upfilesize > $this->filesize) {
false を返します。 //文件过大
}
switch ($upfiletype) { //文件类型
ケース「画像/jpeg」:
$type = 'jpg';
休憩;
ケース「画像/pjpeg」:
$type = 'jpg';
休憩;
ケース「画像/png」:
$type = 'png';
休憩;
ケース「画像/GIF」:
$type = 'gif';
休憩;
}
if (!isset ($type)) {
false を返します。 //このタイプはサポートしません
}
if (!is_uploaded_file($upfiletmpname) または !is_file($upfiletmpname)) {
false を返します;
; //文件不是经过正规上传的;
}
if ($this->upfileerror != 0) {
false を返します。 //その他错误
}
if ($this->upfileerror == 0) {
if (!file_exists($upfiletmpname)) {
false を返します。 //一時文は存在しません
} その他 {
$filename = date("ymdhis", time() + 3600 * 8); //图片已当時刻间命名
$filename = $this->ファイルパス 。 $ファイル名 。 「。」 。 $type;
if (!move_uploaded_file($upfiletmpname, $filename)) {
false を返します。 //文が移動中に紛失しました
} その他 {
if ($this->india == true) {
$this->goindia($filename, $type,true);
} その他 {
if ($this->reimagesize[0] == true) {
$this->goreimagesize($filename, $type);
} その他 {
true を返します。 //上传成功!
リンク解除($upfiletmpname);
}
}
}}
}}
}
//ウォーターマーク処理を追加
function goindia($filename, $filetype,$reimage=false) {
if (!file_exists($filename)) {
$this->reerror(7); //透かしを入れるファイルが存在しません
} その他 {
if ($filetype == "jpg") {
$im = imagecreatefromjpeg($filename);
他
If ($filetype == "gif") {
$im = imagecreatefromgif($filename);
他
If ($filetype == "png") {
$im = imagecreatefrompng($filename);
}
if ($this->indiatext != "") { //ウォーターマークテキストが空でない場合
$textcolor = imagecolorallocate($im, $this->r, $this->g, $this->b) // テキストの色を設定します
Imagestring($im, $this->fontsize, $this->indiatextx, $this->indiatexty, $this->indiatext, $textcolor); // 画像にテキストを書き込みます
}
if ($this->indiaimage != "") {//ウォーターマーク画像が空でない場合
$indiaimagetype = getimagesize($this->indiaimage);
$logow = $indiaimagetype[0] //ウォーターマーク画像の幅を取得します
; $logoh = $indiaimagetype[1] //ウォーターマーク画像の高さを取得します
; Switch ($indiaimagetype[2]) { //ウォーターマーク画像の形式を決定します
ケース 1:
$indiaimagetype = "gif";
$logo = imagecreatefromgif($this->indiaimage);
休憩;
ケース 2:
$indiaimagetype = "jpg";
$logo = imagecreatefromjpeg($this->indiaimage);
休憩;
ケース 3:
$indiaimagetype = "png";
$logo = imagecreatefrompng($this->indiaimage);
休憩;
}
Imagealphablending($im, true) //カラーブレンドモードをオンにする
Imagecopy($im, $logo, $this->indiaimagex, $this->indiaimagey, 0, 0, $logow, $logoh);
画像破壊($im);
Imagedestroy($logo);
}
}
if ($this->indiapath == "") { //ウォーターマークの保存アドレスが空でない場合
if ($filetype == "jpg") {
Imagejpeg($im, $filename);
他
If ($filetype == "gif") {
Imagegif($im, $filename);
他
If ($filetype == "png") {
Imagepng($im, $filename);
}
if($reimage == true){
$this->goreimagesize($filename,$filetype);
}その他{
true を返します // ウォーターマークが正常に追加されました
}
} その他 {
if (!file_exists($this->indiapath)) {
mkdir($this->インドパス);
return false //再アップロードしてください
} その他 {
$indianame = ベース名($filename);
$indianame = $this->indiapath .
If ($filetype == "jpg") {
Imagejpeg($im, $indianame);
他
If ($filetype == "gif") {
Imagegif($im, $indianame);
他
If ($filetype == "png") {
Imagepng($im, $indianame);
}
If($reimage == true){
$this->goreimagesize($indianame,$filetype);
エコー $indianame;
}その他{
true を返します // ウォーターマークが正常に追加されました
}
}
}
}
function goreimagesize($filename, $filetype) {
if (!file_exists($filename)) {
Return false; //サムネイルとして生成する画像が存在しません
} その他 {
if ($filetype == 'jpg') {
$reimage = imagecreatefromjpeg($filename);
}
elseif ($filetype == 'png') {
$reimage = imagecreatefrompng($filename);
他
If ($filetype == 'gif') {
$reimage = imagecreatefromgif($filename);
}
if (isset ($reimage)) {
$srcimagetype = getimagesize($filename);
$srcimagetypew = $srcimagetype[0] //元の画像の幅を取得します
; $srcimagetypeh = $srcimagetype[1] //元の画像の高さを取得します
; $reim = imagecreatetruecolor($this->reimagesize[1], $this->reimagesize[2]);
Imagecopyresize($reim, $reimage, 0, 0, 0, 0, $this->reimagesize[1], $this->reimagesize[2], $srcimagetypew, $srcimagetypeh);
$reimagepath = $this->reimagesize[3];
If ($reimagepath != "") { //ウォーターマーク保存アドレスが空でない場合
If (!file_exists($reimagepath)) {
mkdir($reimagepath);
} その他 {
$reimagename = ベース名($ファイル名);
$reimagename = $reimagepath . $reimagename;
If ($filetype == "gif")
Imagegif($reim, $reimagename);
その他
if ($filetype == "jpg")
Imagejpeg($reim, $reimagename);
その他
if ($filetype == "png")
Imagepng($reim, $reimagename);
true を返します;
}
} その他 {
$filename = ベース名($filename);
If($this->indiapath == ""){
$filename = $this->filepath."r_" . }その他{
$filename = $this->indiapath."r_" . $filename;
}
If ($filetype == "gif")
Imagegif($reim, $filename);
その他
If ($filetype == "jpg")
Imagejpeg($reim, $filename);
その他
if ($filetype == "png")
Imagepng($reim, $filename);
true を返します;
}
}
}
}
if ($_post["送信"]) {
$file = $_files['uploadfile'];
$upfile = 新しい upfile();
echo $upfile->uploadfile($file);
}
?>
フォーム>

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

Dreamweaver Mac版
ビジュアル Web 開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。
