自動名前変更、画像処理など、まだ追加されていない機能がいくつかあります。必要に応じて自分で追加できます。
使用:
$up = new upfile(ROOT_PATH.'data/'.date( "Ym",time()), array('gif','jpg','jpeg'),true);
$fileimg = $up->upload($_FILES['img']);//Returnアップロードされたファイル名の配列、$_FILES[ 'img'] はアップロードされたファイルです
$up->log を使用してアップロード情報を表示できます
//========。 ============ ================================
// ファイル名: upfile .class.php
// 概要: ファイル アップロード クラス
// 著者: millken (Lost Lincoln)
// LastModifed: 2008-6-4
// copyright (c)2008 millken@gmail.com
//== ============ =====================================
if(!define('OK'))exit (__FILE__.'アクセスが拒否されました');
public $ExtensionFileFormat = array();
private $ImageFileFormat = array( 'gif','bmp','jpg', 'jpe','jpeg','png');
private $OtherFileFormat = array('zip','pdf','rar','xls','doc ','ppt','csv');
private $savePath = './upfiles/';
private $overwrite = false;ファイルの最大バイト サイズ、0 の場合、サイズ制限はありません
private $ ext;
/* コンストラクター
* (string)$savePath ファイルの保存パス、デフォルトは $attachment_path です。 * (array)$extensionFileFormat アップロードされたファイルの拡張子をカスタマイズします。設定されていない場合は $ImageFileFormat || $OtherFileFormat
* (bool)$overwrite 同じ名前のファイルを上書きするかどうか
*/
public function __construct( $savePath='',$extensionFileFormat = array(),$overwrite = false) {
$this->savePath = empty($savePath)?$this->attachment_pathsavePath.'/'; extensionFileFormat = is_array($extensionFileFormat)?$extensionFileFormat:array();
$this->overwrite = is_bool($overwrite )?$overwrite:false;
}
/*アップロード関数
* (array)$files の配列アップロードするファイル$_FILES['attach']
* (number)$maxSize ファイルの最大バイト数、デフォルトは 0 アップロードサイズに制限なし
*/
public function Upload($files,$maxSize=0) ) {
$this->maxSize = is_numeric($maxSize)?$maxSize:0;
if(isset($files) && is_array ($files)) {
if(is_array($files['name']) ) {
foreach($files as $key => $var) {
foreach($var as $id => $val) {
$attachments[$id][$key] = $val
}
; }
} else {
$attachments[] = $files;
}
}
self::check_file_type($attachments);
if(empty($this->filelist)) {
$this->log . = "アップロードするファイルのリストが空です。 n";
return array();
}
if(!self::makeDirectory() || !@is_writable($this->savePath)) {
$this->log .= $this-> savePath . "作成できないか、その権限が書き込み可能ではありません。 n";
return array();
}
$filearray = array();
foreach($this->filelist as $k=>$f) {
if($this->maxSize && $f ['size']>$this->maxSize) {
$this->log .= $f['name'] . "サイズが設定値を超えています:" . n";
}elseif($this->overwrite == false && file_exists($this->savePath . $f['name'])) {
$this->log .= $f[ 'name '] . "ディレクトリに既に存在します:" . $this->savePath . "n" {
@unlink($this->savePath . $f['name']); @move_uploaded_file($f['tmp_name'],$this->savePath . mb_convert_encoding($f['name'],'gbk','utf-8'))) {//エンコーディング変換が実行されない場合、中国語はサポートされません
$this->log .= $f['name'] . "ディレクトリに正常にアップロードされました:". $this->savePath ."n";
$filearray[$k] = $ this ->savePath . $f['name'];
$this->log .= $f['name'] 。 n";
}
}
}
return $filearray;
}
/*ファイルの種類を検出
*(array)$files ファイル配列
*/
private function check_file_type($files) {
$this-> ; ファイルリスト = array();
foreach($key=>$file としての $file) {
if($file['error'] == 0) {
$ext = strto lower(substr($file['name) ' ], strrpos($file['name'], '.') + 1));
$str = @file_get_contents($file['tmp_name'],FALSE,NULL,0,20); in_array ($ext,array('jpg','jpeg')) && substr($str ,0, 3) !== "xFFxD8xFF") || ($ext == 'gif' && substr($str ,0) , 4) !== 'GIF8') || ($ext == 'png' && substr($str ,0, 8) !== "x89x50x4Ex47x0Dx0Ax1Ax0A") || ($ext == 'bmp' && substr( $ str ,0, 2) !== 'BM') || ($ext == 'swf' && (substr($str ,0, 3) !== 'CWS' || substr($str ,0, 3 ) !== 'FWS')) || ($ext == 'zip' && substr($str ,0, 4) !== "PKx03x04") || ($ext == 'rar' && substr( $ str ,0, 4) !== 'Rar!') || ($ext == 'pdf' && substr($str ,0, 4) !== "x25PDF") || ($ext == ' chm ' && substr($str ,0, 4) !== 'ITSF') || ($ext == 'rm' && substr($str ,0, 4) !== "x2ERMF") || ext == 'exe' && substr($str ,0, 2) !== "MZ") || (in_array($ext,array('doc','xls','ppt')) && substr($ str ,0, 4) !== "xD0xCFx11xE0")) {
$this->log .= $file['name'] . "ファイルの種類がファイルの内容と一致しません。n";
}elseif((!empty($this->extensionFileFormat) && in_array($ext,$this->extensionFileFormat)) || (empty($this->extensionFileFormat) && (in_array($ext) ,$this->ImageFileFormat) || in_array($ext,$this->OtherFileFormat)))) {
$this->filelist[$key] = $file; ;log .= $file['name'] . "不符合上転送ファイルの種類。n";
@unlink($file['tmp_name']);
*
*/
プライベート関数 makeDirectory() {
$directoryName = str_replace("\","/", $this->savePath);
$dirNames =explode('/', $directoryName); total = count($dirNames);
$temp = '';
for($i{
$temp .= $dirNames[$i].'/';
if (!is_dir($temp))
{
$oldmask = @umask(0);
if (!@mkdir($temp, 0777))
@umask($oldmask); ;
if(is_dir($this->savePath)) {
true を返す
}
}
;
以上は、側面の内容を含む、PHP5+UTF8 上で転送されるマルチファイルであり、PHP 教程に関心のある友人の助けになることを望みます。

thesecrettokeepingaphp-poweredwebsterunningsmootlyunderheavyloadinvolvesseveralkeystrategies:1)emform opcodecoduceSciptionexecutiontime、2)aatabasequerycachingwithiThing withiThistolessendavasoload、

コードをより明確かつ維持しやすくするため、依存関係が関心(DI)に注意する必要があります。 1)DIは、クラスを切り離すことにより、よりモジュール化されます。2)テストとコードの柔軟性の利便性を向上させ、3)DIコンテナを使用して複雑な依存関係を管理しますが、パフォーマンスの影響と円形の依存関係に注意してください。

はい、最適化されたAphPossibleandessention.1)CachingingusapCutoredatedAtabaseload.2)最適化、効率的なQueries、およびConnectionPooling.3)EnhcodeCodewithBultinctions、Avoididingglobalbariables、およびUsingopcodeching

keyStrategIestsoSificlyvoostphpappliceperformanceare:1)useopcodecachinglikeToreexecutiontime、2)最適化abaseの相互作用とプロペラインデックス、3)3)構成

aphpDependencyInjectionContaineriSATOULTAINATINAGECLASSDEPTINCIES、強化測定性、テスト可能性、および維持可能性。

SELECT DEPENTENCINGINOFCENT(DI)大規模なアプリケーションの場合、ServicElocatorは小さなプロジェクトまたはプロトタイプに適しています。 1)DIは、コンストラクターインジェクションを通じてコードのテスト可能性とモジュール性を改善します。 2)ServiceLocatorは、センター登録を通じてサービスを取得します。これは便利ですが、コードカップリングの増加につながる可能性があります。

phpapplicationscanbeoptimizedforspeedandEfficiencyby:1)enabingopcacheinphp.ini、2)PreparedStatementswithpordatabasequeriesを使用して、3)LoopswithArray_filterandarray_mapfordataprocessing、4)の構成ngincasaSearverseproxy、5)

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

メモ帳++7.3.1
使いやすく無料のコードエディター

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

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

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