PHP画像アップロードコード(サムネイル生成・ウォーターマーク追加機能付き)_PHPチュートリアル
この画像アップロードソースコードは、画像をアップロードすることができ、サムネイルを生成し、アップロードされた画像に透かしを追加する機能も備えており、完璧な画像アップローダーと言えます。
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);
}
?>
フォーム>

BestappRoachforseminginphpisusingthephpmailerlibrarydueToitsReliability、featurrichness、andeaseofuse.phpmailerSupportssmtpは、detairederorhandlingを提供します

依存関係注射(DI)を使用する理由は、コードのゆるい結合、テスト可能性、および保守性を促進するためです。 1)コンストラクターを使用して依存関係を注入します。2)サービスロケーターの使用を避け、3)依存関係噴射コンテナを使用して依存関係を管理する、4)依存関係を注入することでテスト可能性を向上させる、5)注入依存性を回避、6)パフォーマンスに対するDIの影響を考慮します。

phpperformancetuningisucial cuseenhancess andandandadsand。

bestpracticesforsendingemails securlyinphpinclude:1)sutureconsmttarttlsencryptionとの使用の使用、2)検証およびサンシジン化のinputStopReventinjectuctacks、3)adinitivedinitivedInemailsopenslsl、4)adlinglinglingemailoaに

tooptimizephpapplicationsforporformance、usecaching、databaseoptimization、opcodecaching、andserverconfiguration.1)cachingwithedatedatedatafethtimes.2)最適化バイズビーインデキシング、readedandandandwriteoperations.3)

依存関係の依存性、テスト可能性、および維持可能性の依存性の依存性の依存性、および維持可能性は、エクステルンド依存性を維持する可能性があります

PHPパフォーマンスの最適化は、次の手順を通じて実現できます。1)スクリプトの上部にrequire_onceまたはinclude_onceを使用して、ファイルの負荷数を減らすことができます。 2)プリプロセシングステートメントとバッチ処理を使用して、データベースクエリの数を減らします。 3)OpCodeキャッシュのOpCacheを構成します。 4)PHP-FPM最適化プロセス管理を有効にして構成します。 5)CDNを使用して静的リソースを配布します。 6)コードパフォーマンス分析には、XdebugまたはBlackfireを使用します。 7)配列などの効率的なデータ構造を選択します。 8)最適化実行のためのモジュラーコードを記述します。

opcodeCachingsificlyprovesppherformanceBycachingCompiledCode、reducingServerloadandResponsetimes.1)itStoresPhpCodeInMemory、バイパス補助補強団体


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

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

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

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