国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

ホームページ バックエンド開(kāi)発 PHPチュートリアル codeigniter チュートリアル 複數(shù)ファイルのアップロードの使用例_PHP チュートリアル

codeigniter チュートリアル 複數(shù)ファイルのアップロードの使用例_PHP チュートリアル

Jul 13, 2016 am 10:39 AM
codeigniter 複數(shù)のファイルのアップロード

コードをコピーします コードは次のとおりです:

/**
* Multi-Upload
*
* Extends CodeIgniters native Upload class to add support for multiple
* uploads.
*
* @package CodeIgniter
* @subpackage Libraries
* @category Uploads
*/
class MY_Upload extends CI_Upload {


/**
* Properties
*/
protected $_multi_upload_data = array();
protected $_multi_file_name_override = "";


/**
* Initialize preferences
*
* @access public
* @param array
* @return void
*/
public function initialize($config = array()){
//Upload default settings.
$defaults = array(
"max_size" => 0,
?????????"max_width"???=> 0,
?????????"max_height"??=> 0,
?????????"max_filename"??=> 0,
?????????"allowed_types"??=> "",
?????????"file_temp"???=> "",
?????????"file_name"???=> "",
?????????"orig_name"???=> "",
?????????"file_type"???=> "",
?????????"file_size"???=> "",
?????????"file_ext"???=> "",
?????????"upload_path"??=> "",
?????????"overwrite"???=> FALSE,
?????????"encrypt_name"??=> FALSE,
?????????"is_image"???=> FALSE,
?????????"image_width"??=> "",
?????????"image_height"??=> "",
?????????"image_type"??=> "",
?????????"image_size_str"?=> "",
?????????"error_msg"???=> array(),
?????????"mimes"????=> array(),
?????????"remove_spaces"??=> TRUE,
?????????"xss_clean"???=> FALSE,
?????????"temp_prefix"??=> "temp_file_",
?????????"client_name"??=> ""
????????);

?????//Set each configuration.
?????foreach($defaults as $key => $val){
??????if(isset($config[$key])){
???????$method = "set_{$key}";
???????if(method_exists($this, $method)){
????????$this->$method($config[$key]);
???????} else {
????????$this->$key = $config[$key];
???????}
??????} else {
???????$this->$key = $val;
??????}
?????}

?????//Check if file_name was provided.
?????if(!empty($this->file_name)){
??????//Multiple file upload.
??????if(is_array($this->file_name)){
???????//Clear file name override.
???????$this->_file_name_override = "";

???????//Set multiple file name override.
???????$this->_multi_file_name_override = $this->file_name;
??????//Single file upload.
??????} else {
???????//Set file name override.
???????$this->_file_name_override = $this->file_name;

???????//Clear multiple file name override.
???????$this->_multi_file_name_override = "";
??????}
?????}
????}


???/**
??? * File MIME Type
??? *
??? * Detects the (actual) MIME type of the uploaded file, if possible.
??? * The input array is expected to be $_FILES[$field].
??? *
??? * In the case of multiple uploads, a optional second argument may be
??? * passed specifying which array element of the $_FILES[$field] array
??? * elements should be referenced (name, type, tmp_name, etc).
??? *
??? * @access?protected
??? * @param?$file?array
??? * @param?$count?int
??? * @return?void
??? */
????protected function _file_mime_type($file, $count=0){
?????//Mutliple file?
?????if(is_array($file["name"])){
??????$tmp_name = $file["tmp_name"][$count];
??????$type = $file["type"][$count];
?????//Single file.
?????} else {
??????$tmp_name = $file["tmp_name"];
??????$type = $file["type"];
?????}

?????//We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii).
?????$regexp = "/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/";

?????/* Fileinfo Extension - most reliable method.
????? *
????? * Unfortunately, prior to PHP 5.3 - it's only available as a PECL extension and the
????? * more convenient FILEINFO_MIME_TYPE flag doesn't exist.
????? */
????? ?if(function_exists("finfo_file")){
????? ??$finfo = finfo_open(FILEINFO_MIME);
???????if(is_resource($finfo)){
????????$mime = @finfo_file($finfo, $tmp_name);
????????finfo_close($finfo);

????????/* According to the comments section of the PHP manual page,
???????? * it is possible that this function returns an empty string
???????? * for some files (e.g. if they don't exist in the magic MIME database).
???????? */
???????? ?if(is_string($mime) && preg_match($regexp, $mime, $matches)){
???????? ??$this->file_type = $matches[1];
??????????return;
???????? ?}
???????}
????? ?}

?????/* This is an ugly hack, but UNIX-type systems provide a "native" way to detect the file type,
????? * which is still more secure than depending on the value of $_FILES[$field]['type'], and as it
????? * was reported in issue #750 (https://github.com/EllisLab/CodeIgniter/issues/750) - it's better
????? * than mime_content_type() as well, hence the attempts to try calling the command line with
????? * three different functions.
????? *
????? * Notes:
????? *?- the DIRECTORY_SEPARATOR comparison ensures that we're not on a Windows system
????? *?- many system admins would disable the exec(), shell_exec(), popen() and similar functions
????? *?? due to security concerns, hence the function_exists() checks
????? */
????? ?if(DIRECTORY_SEPARATOR !== "\\"){
????? ??$cmd = "file --brief --mime ".escapeshellarg($tmp_name)." 2>&1";

???????if(function_exists("exec")){
????????/* This might look confusing, as $mime is being populated with all of the output when set in the second parameter.
???????? * However, we only neeed the last line, which is the actual return value of exec(), and as such - it overwrites
???????? * anything that could already be set for $mime previously. This effectively makes the second parameter a dummy
???????? * value, which is only put to allow us to get the return status code.
???????? */
?????????$mime = @exec($cmd, $mime, $return_status);
?????????if($return_status === 0 && is_string($mime) && preg_match($regexp, $mime, $matches)){
??????????$this->file_type = $matches[1];
??????????return;
?????????}
???????}
????? ?}

??????if((bool)@ini_get("safe_mode") === FALSE && function_exists("shell_exec")){
???????$mime = @shell_exec($cmd);
???????if(strlen($mime) > 0){
????????$mime = explode("\n", trim($mime));
????????if(preg_match($regexp, $mime[(count($mime) - 1)], $matches)){
?????????$this->file_type = $matches[1];
?????????return;
????????}
???????}
??????}

??????if(function_exists("popen")){
???????$proc = @popen($cmd, "r");
???????if(is_resource($proc)){
????????$mime = @fread($proc, 512);
????????@pclose($proc);
????????if($mime !== FALSE){
?????????$mime = explode("\n", trim($mime));
?????????if(preg_match($regexp, $mime[(count($mime) - 1)], $matches)){
??????????$this->file_type = $matches[1];
??????????return;
?????????}
????????}
???????}
??????}

??????//Fall back to the deprecated mime_content_type(), if available (still better than $_FILES[$field]["type"])
??????if(function_exists("mime_content_type")){
???????$this->file_type = @mime_content_type($tmp_name);
???????//It's possible that mime_content_type() returns FALSE or an empty string.
???????if(strlen($this->file_type) > 0){
????????return;
???????}
??????}

??????//If all else fails, use $_FILES default mime type.
??????$this->file_type = $type;
????}


???/**
??? * Set Multiple Upload Data
??? *
??? * @access?protected
??? * @return?void
??? */
????protected function set_multi_upload_data(){
?????$this->_multi_upload_data[] = array(
??????"file_name"???=> $this->file_name,
??????"file_type"???=> $this->file_type,
??????"file_path"???=> $this->upload_path,
??????"full_path"???=> $this->upload_path.$this->file_name,
??????"raw_name"???=> str_replace($this->file_ext, "", $this->file_name),
??????"orig_name"???=> $this->orig_name,
??????"client_name"??=> $this->client_name,
??????"file_ext"???=> $this->file_ext,
??????"file_size"???=> $this->file_size,
??????"is_image"???=> $this->is_image(),
??????"image_width"??=> $this->image_width,
??????"image_height"??=> $this->image_height,
??????"image_type"??=> $this->image_type,
??????"image_size_str"?=> $this->image_size_str
?????);
????}


???/**
??? * Get Multiple Upload Data
??? *
??? * @access?public
??? * @return?array
??? */
????public function get_multi_upload_data(){
?????return $this->_multi_upload_data;
????}


???/**
??? * Multile File Upload
??? *
??? * @access?public
??? * @param?string
??? * @return?mixed
??? */
????public function do_multi_upload($field){
?????//Is $_FILES[$field] set? If not, no reason to continue.
?????if(!isset($_FILES[$field])){ return false; }

?????//Is this really a multi upload?
?????if(!is_array($_FILES[$field]["name"])){
??????//Fallback to do_upload method.
??????return $this->do_upload($field);
?????}

?????//Is the upload path valid?
?????if(!$this->validate_upload_path()){
??????//Errors will already be set by validate_upload_path() so just return FALSE
??????return FALSE;
?????}

?????//Every file will have a separate entry in each of the $_FILES associative array elements (name, type, etc).
?????//Loop through $_FILES[$field]["name"] as representative of total number of files. Use count as key in
?????//corresponding elements of the $_FILES[$field] elements.
?????for($i=0; $i //Was the file able to be uploaded? If not, determine the reason why.
if(!is_uploaded_file($_FILES[$field]["tmp_name"][$i])){
//Determine error number.
$error = (!isset($_FILES[$field]["error"][$i])) ? 4 : $_FILES[$field]["error"][$i];

//Set error.
switch($error){
//UPLOAD_ERR_INI_SIZE
case 1:
$this->set_error("upload_file_exceeds_limit");
????????break;
????????//UPLOAD_ERR_FORM_SIZE
????????case 2:
?????????$this->set_error("upload_file_exceeds_form_limit");
????????break;
????????//UPLOAD_ERR_PARTIAL
????????case 3:
?????????$this->set_error("upload_file_partial");
????????break;
????????//UPLOAD_ERR_NO_FILE
????????case 4:
?????????$this->set_error("upload_no_file_selected");
????????break;
????????//UPLOAD_ERR_NO_TMP_DIR
????????case 6:
?????????$this->set_error("upload_no_temp_directory");
????????break;
????????//UPLOAD_ERR_CANT_WRITE
????????case 7:
?????????$this->set_error("upload_unable_to_write_file");
????????break;
????????//UPLOAD_ERR_EXTENSION
????????case 8:
?????????$this->set_error("upload_stopped_by_extension");
????????break;
????????default:
?????????$this->set_error("upload_no_file_selected");
????????break;
???????}

???????//Return failed upload.
???????return FALSE;
??????}

??????//Set current file data as class variables.
??????$this->file_temp?= $_FILES[$field]["tmp_name"][$i];
??????$this->file_size?= $_FILES[$field]["size"][$i];
??????$this->_file_mime_type($_FILES[$field], $i);
??????$this->file_type?= preg_replace("/^(.+?);.*$/", "\\1", $this->file_type);
??????$this->file_type?= strtolower(trim(stripslashes($this->file_type), '"'));
??????$this->file_name?= $this->_prep_filename($_FILES[$field]["name"][$i]);
??????$this->file_ext??= $this->get_extension($this->file_name);
??????$this->client_name?= $this->file_name;

??????//Is the file type allowed to be uploaded?
??????if(!$this->is_allowed_filetype()){
???????$this->set_error("upload_invalid_filetype");
???????return FALSE;
??????}

??????//If we're overriding, let's now make sure the new name and type is allowed.
??????//Check if a filename was supplied for the current file. Otherwise, use it's given name.
??????if(!empty($this->_multi_file_name_override[$i])){
???????$this->file_name = $this->_prep_filename($this->_multi_file_name_override[$i]);

???????//If no extension was provided in the file_name config item, use the uploaded one.
???????if(strpos($this->_multi_file_name_override[$i], ".") === FALSE){
????????$this->file_name .= $this->file_ext;
???????//An extension was provided, lets have it!
???????} else {
????????$this->file_ext = $this->get_extension($this->_multi_file_name_override[$i]);
???????}

???????if(!$this->is_allowed_filetype(TRUE)){
????????$this->set_error("upload_invalid_filetype");
????????return FALSE;
???????}
??????}

??????//Convert the file size to kilobytes.
??????if($this->file_size > 0){
???????$this->file_size = round($this->file_size/1024, 2);
??????}

??????//Is the file size within the allowed maximum?
??????if(!$this->is_allowed_filesize()){
???????$this->set_error("upload_invalid_filesize");
???????return FALSE;
??????}

??????//Are the image dimensions within the allowed size?
??????//Note: This can fail if the server has an open_basdir restriction.
??????if(!$this->is_allowed_dimensions()){
???????$this->set_error("upload_invalid_dimensions");
???????return FALSE;
??????}

??????//Sanitize the file name for security.
??????$this->file_name = $this->clean_file_name($this->file_name);

??????//Truncate the file name if it's too long
??????if($this->max_filename > 0){
???????$this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename);
??????}

??????//Remove white spaces in the name
??????if($this->remove_spaces == TRUE){
???????$this->file_name = preg_replace("/\s+/", "_", $this->file_name);
??????}

??????/* Validate the file name
?????? * This function appends an number onto the end of
?????? * the file if one with the same name already exists.
?????? * If it returns false there was a problem.
?????? */
???????$this->orig_name = $this->file_name;
???????if($this->overwrite == FALSE){
????????$this->file_name = $this->set_filename($this->upload_path, $this->file_name);
????????if($this->file_name === FALSE){
?????????return FALSE;
????????}
???????}

/* XSS ハッキング フィルターを通してファイルを?qū)g行します
* これにより、悪意のあるコードがファイル內(nèi)に埋め込まれる
* ことを防ぎます。? スクリプトは、簡(jiǎn)単に畫(huà)像またはその他のファイルタイプとして偽裝できます。 */
if($ this-> xss_clean){
if($ this-> do_xss_clean()=== {
$ this-&gt ;set_error("upload_unable_to_write_file");
return FALSE;
}
}

/* ファイルを最終的な宛先に移動(dòng)します

* 異なるサーバー構(gòu)成に対処するため

* 最初に copy() を使用してみます。? それが失敗した場(chǎng)合
* move_uploaded_file() を使用します。? 2 つのうちの 1 つは必要です
* ほとんどの環(huán)境で確実に動(dòng)作します
*/
if(!@copy($this->file_temp, $this->upload_path.$this->file_name)){
if(!@ move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)){
$this->set_error("upload_destination_error");
return FALSE;
}
}

/* 最終的な畫(huà)像の寸法を設(shè)定します

* 畫(huà)像の幅/高さを設(shè)定します (

* ファイルが畫(huà)像であると仮定します)。? この情報(bào)は
* 「data」関數(shù)で使用します。
*/
$this->set_image_properties($this->upload_path.$this->file_name);

//現(xiàn)在のファイルデータを multi_file_upload_data に設(shè)定します。

$this->set_multi_upload_data();

}

//すべてのファイルアップロードデータを返します。

return TRUE;

}
}


http://www.bkjia.com/PHPjc/733059.html

tru??ehttp://www.bkjia.com/PHPjc/733059.html技術(shù)記事例: ?php if(!define("BASEPATH")){ exit("直接スクリプト アクセスは許可されません"); } /** * マルチアップロード * * CodeIgniters のネイティブ Upload クラスを拡張してサポートを追加します...
このウェブサイトの聲明
この記事の內(nèi)容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰屬します。このサイトは、それに相當(dāng)する法的責(zé)任を負(fù)いません。盜作または侵害の疑いのあるコンテンツを見(jiàn)つけた場(chǎng)合は、admin@php.cn までご連絡(luò)ください。

ホットAIツール

Undress AI Tool

Undress AI Tool

脫衣畫(huà)像を無(wú)料で

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード寫(xiě)真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

寫(xiě)真から衣服を削除するオンライン AI ツール。

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無(wú)料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡(jiǎn)単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無(wú)料のコードエディター

SublimeText3 中國(guó)語(yǔ)版

SublimeText3 中國(guó)語(yǔ)版

中國(guó)語(yǔ)版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強(qiáng)力な PHP 統(tǒng)合開(kāi)発環(huán)境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開(kāi)発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

CodeIgniter でカスタムミドルウェアを?qū)g裝する方法 CodeIgniter でカスタムミドルウェアを?qū)g裝する方法 Jul 29, 2023 am 10:53 AM

CodeIgniter でカスタム ミドルウェアを?qū)g裝する方法 はじめに: 最新の Web 開(kāi)発では、ミドルウェアがアプリケーションで重要な役割を果たします。これらは、リクエストがコントローラーに到達(dá)する前または後に、共有処理ロジックを?qū)g行するために使用できます。 CodeIgniter は、人気のある PHP フレームワークとして、ミドルウェアの使用もサポートしています。この記事では、CodeIgniter でカスタム ミドルウェアを?qū)g裝する方法を紹介し、簡(jiǎn)単なコード例を示します。ミドルウェアの概要: ミドルウェアは一種のリクエストです

CodeIgniter ミドルウェア: アプリケーションの応答性とページのレンダリングを高速化します。 CodeIgniter ミドルウェア: アプリケーションの応答性とページのレンダリングを高速化します。 Jul 28, 2023 pm 06:51 PM

CodeIgniter ミドルウェア: アプリケーションの応答性とページ レンダリングの高速化 概要: Web アプリケーションの複雑さと対話性が増大し続ける中、開(kāi)発者はアプリケーションのパフォーマンスと応答性を向上させるために、より効率的でスケーラブルなソリューションを使用する必要があります。 CodeIgniter (CI) は、多くの便利な機(jī)能を提供する軽量の PHP ベースのフレームワークであり、その 1 つがミドルウェアです。ミドルウェアは、リクエストがコントローラーに到達(dá)する前または後に実行される一連のタスクです。この記事では使い方を紹介します

CodeIgniter フレームワークでデータベース クエリ ビルダー (Query Builder) を使用する方法 CodeIgniter フレームワークでデータベース クエリ ビルダー (Query Builder) を使用する方法 Jul 28, 2023 pm 11:13 PM

CodeIgniter フレームワークでデータベース クエリ ビルダー (QueryBuilder) を使用する方法の紹介: CodeIgniter は、開(kāi)発者が Web アプリケーション開(kāi)発を容易にするための強(qiáng)力なツールとライブラリを多數(shù)提供する軽量の PHP フレームワークです。最も印象的な機(jī)能の 1 つは、データベース クエリ ビルダー (QueryBuilder) です。これは、データベース クエリ ステートメントを構(gòu)築および実行するための簡(jiǎn)潔かつ強(qiáng)力な方法を提供します。この記事ではCoの使い方を紹介します。

PHP 開(kāi)発: CodeIgniter を使用して MVC パターンと RESTful API を?qū)g裝する PHP 開(kāi)発: CodeIgniter を使用して MVC パターンと RESTful API を?qū)g裝する Jun 16, 2023 am 08:09 AM

Web アプリケーションは進(jìn)化し??続けるため、アプリケーションをより迅速かつ効率的に開(kāi)発することが重要です。また、RESTful API は Web アプリケーションで広く使用されているため、開(kāi)発者は RESTful API の作成および実裝方法を理解する必要があります。この記事では、CodeIgniter フレームワークを使用して MVC パターンと RESTful API を?qū)g裝する方法について説明します。 MVC パターン MVC (Model-Vie) の概要

HTML フォームで複數(shù)のファイルのアップロードを許可する方法 HTML フォームで複數(shù)のファイルのアップロードを許可する方法 Aug 28, 2023 pm 08:25 PM

この記事では、HTML フォームで複數(shù)のファイルのアップロードを許可する方法を?qū)Wびます。HTML フォームで複數(shù)のファイルのアップロードを許可するには、複數(shù)の屬性を使用します。電子メールとファイルの入力タイプには、いくつかのプロパティが使用できます。ユーザーが Web サイトにファイルをアップロードできるようにしたい場(chǎng)合は、ファイル選択ボックスとも呼ばれるファイル アップロード ボックスを使用する必要があります。これは <in を使用して作成されます。

PHP フレームワーク CodeIgniter を使用して、便利なコミュニケーション サービスを提供するリアルタイム チャット アプリケーションを開(kāi)発します。 PHP フレームワーク CodeIgniter を使用して、便利なコミュニケーション サービスを提供するリアルタイム チャット アプリケーションを開(kāi)発します。 Jun 27, 2023 pm 02:49 PM

モバイル インターネットの発展に伴い、インスタント メッセージングの重要性と人気がますます高まっています。多くの企業(yè)にとって、ライブ チャットはコミュニケーション サービスに似ており、ビジネス上の問(wèn)題を迅速かつ効果的に解決できる便利なコミュニケーション手段を提供します。これを踏まえて、この記事ではPHPフレームワークCodeIgniterを使ってリアルタイムチャットアプリケーションを開(kāi)発する方法を紹介します。 CodeIgniter フレームワークを理解する CodeIgniter は、開(kāi)発者を迅速に支援する一連のシンプルなツールとライブラリを提供する軽量の PHP フレームワークです。

PHPでCodeIgniter5フレームワークを使用するにはどうすればよいですか? PHPでCodeIgniter5フレームワークを使用するにはどうすればよいですか? Jun 01, 2023 am 11:21 AM

CodeIgniter は、MVC アーキテクチャを使用して迅速な開(kāi)発をサポートし、一般的なタスクを簡(jiǎn)素化する軽量の PHP フレームワークです。 CodeIgniter5 はフレームワークの最新バージョンであり、多くの新機(jī)能と改善點(diǎn)が提供されています。この記事では、CodeIgniter5 フレームワークを使用して簡(jiǎn)単な Web アプリケーションを構(gòu)築する方法を紹介します。ステップ 1: CodeIgniter5 をインストールする CodeIgniter5 のダウンロードとインストールは非常に簡(jiǎn)単で、次の手順に従うだけです。 最新バージョンをダウンロードします。

CodeIgniter ミドルウェア: 安全なファイルのアップロードおよびダウンロード機(jī)能を提供します。 CodeIgniter ミドルウェア: 安全なファイルのアップロードおよびダウンロード機(jī)能を提供します。 Aug 01, 2023 pm 03:01 PM

CodeIgniter ミドルウェア: 安全なファイルのアップロードおよびダウンロード機(jī)能を提供します はじめに: Web アプリケーション開(kāi)発のプロセスにおいて、ファイルのアップロードとダウンロードは非常に一般的な機(jī)能です。ただし、セキュリティ上の理由から、ファイルのアップロードとダウンロードの処理には追加のセキュリティ対策が必要になることがよくあります。 CodeIgniter は、開(kāi)発者による安全で信頼性の高い Web アプリケーションの構(gòu)築をサポートする豊富なツールとライブラリを提供する人気の PHP フレームワークです。この記事では、CodeIgniter ミドルウェアを使用して安全なファイルを?qū)g裝する方法を紹介します。

See all articles