現在終於到了我們的第三個文件,include.php 它為程式建立起一個使用者介面。
"include.php" 包含三個表單,一些PHP程式碼取得目前的目錄清單並將它們存入三個變數
$files (包括目前目錄下的檔案),
$ file_sizes (對應的檔案大小),
and $dirs (包含子目錄名)
第一個表單使用$dirs 產生一個下拉式目錄列表,對應於「action=CWD」。
第二個表單使用$files $file_sizes建立一個可用的檔案列表,每個檔案使用一個checkbox。這個表單的action對應到"action=Delete" and "action=Download"
第三個表單用來上傳一個檔案到FTP站點,如下:
--------- -------------------------------------------------- ---------------------
---------------------- -------------------------------------------------- --------
當PHP以這種方式接收到一個檔案名,一些變數就產生了,這些變數指定檔案的大小,一個臨時的檔案名稱以及檔案的類型,最初的檔案名存在$upfile_name,一旦上傳後檔案名稱便存入$upfile中(這個變數是由PHP自己建立的)
透過這些訊息,我們就可以建立以下的語句了:
------ -------------------------------------------------- ------------------------
ftp_put($result, $upfile_name, $upfile, FTP_BINARY);
------ -------------------------------------------------- ------------------------
以下是代碼列表:
--------------- -------------------------------------------------- ---------------
- -------------------------------------------------- -----------------------------
------------------ -------------------------------------------------- ------------
/*
------------------ -------------------------------------------------- ------------
DISCLAIMER:
This is use-at-your-own-risk code.
It is meant only for illustrative purposes and is not meant for production environments. No warranties of any kind are provided to the user.
You have been warned!
All code copyright Melonfire, 200 atfire. Visfireus .melonfire.com
------------------------------------------- -------------------------------------
*/
// function to connect to FTP server
function connect()
{
global $server, $username, $password;
$conn = ftp_connect($server);
ftp_login($conn,$server);
ftp_login($conn, $username, $password);
return $conn;
}
// main program begins
// check for valid form entries else print errorif (!$server
!$username
!$password)
{
echo "Form data incomplete!";
}
else
{
}
else
{
}
else
{
// connect
$result = connect();
// action: change directory
if ($action == "CWD")
{
// at initial stage $rdir does not exist
// so assume default directory
if (!$rdir)
{
$path = ".";
}
}
}
// get current location $cdir and add it to requested directory $rdir
else
{
$path = $cdir . "/" . $rdir;
}
> >// change to requested directoryftp_chdir($result, $path);}// action: delete file(s)else if ($action = = "Delete"){ftp_chdir($result, $cdir);// loop through selected files and deletefor ($x=0; $x
// 操作:上傳檔案
else if ($action == "上傳")
{
ftp_chdir($result, $cdir);
/// put 文件
/*
更好的主意是使用
$res_code = ftp_put($result, $HTTP_POST_FILES["upfile"]["name"],
$HTTP_POST_FILES[ " upfile"]["tmp_name"], FTP_BINARY);
因為它提供了更高的安全性
*/
$res_code = ftp_put($result, $upfile_name, $upfile, FTP_BINARY);
//檢查狀態並顯示
if ($res_code == 1)
{
$status = "上傳成功!";
}
else
else
{
$status = "上傳錯誤!";
}
}
//建立檔案清單
$filelist = ftp_nlist($result, ". ");
//顯示介面
include("include.php");
//關閉連線
ftp_quit($result);
}
?>
- --- ----------------------------------------------- --- -----------------------------------
------------ ------ -------------------------------------------- ------ ------------
// 取得目前內容location
$here = ftp_pwd($result);
/*
因為ftp_size() 非常慢,特別是在處理
包含目錄中所有檔案的陣列時,
此部分對目前
目錄中的所有檔案執行ftp_size() 並建立三個陣列。
*/
// 檔案陣列
$files = Array() ;
// 目錄陣列
$dirs = Array();
// 檔案大小數組
$file_sizes = Array();
// counters
$file_list_counter = 0;
$dir_list_counter = 0;
$dir_list_counter = 0;
的每個元素是否為($x=0; $x
if (ftp_size($result, $filelist[$x]) != -1)
{
// 建立陣列
$files[$file_list_counter] = $filelist[$x];
$file_sizes[$file_list_counter] = ftp_size($result, $list [$x]);
$file_list_counter ;
}
else
{
$dir_list[$dir_list_counter] = $filelist[$x];
$dir_list_counter> }
}
?>
您目前在
center>
可用目錄:

DependencyInjection(DI)inPHPenhancescodeflexibilityandtestabilitybydecouplingdependencycreationfromusage.ToimplementDIeffectively:1)UseDIcontainersjudiciouslytoavoidover-engineering.2)Avoidconstructoroverloadbylimitingdependenciestothreeorfour.3)Adhe

到Improveyourphpwebsite的實力,UsEthestertate:1)emplastOpCodeCachingWithOpcachetCachetOspeedUpScriptInterpretation.2)優化的atabasequesquesquesquelies berselectingOnlynlynnellynnessaryfields.3)usecachingsystemssslikeremememememcachedisemcachedtoredtoredtoredsatabaseloadch.4)

是的,ItispossibletosendMassemailswithp.1)uselibrarieslikeLikePhpMailerorSwiftMailerForeffitedEmailsending.2)enasledeLaysBetenemailstoavoidSpamflagssspamflags.3))

DependencyInjection(DI)inPHPisadesignpatternthatachievesInversionofControl(IoC)byallowingdependenciestobeinjectedintoclasses,enhancingmodularity,testability,andflexibility.DIdecouplesclassesfromspecificimplementations,makingcodemoremanageableandadapt

使用PHP發送電子郵件的最佳方法包括:1.使用PHP的mail()函數進行基本發送;2.使用PHPMailer庫發送更複雜的HTML郵件;3.使用SendGrid等事務性郵件服務提高可靠性和分析能力。通過這些方法,可以確保郵件不僅到達收件箱,還能吸引收件人。

計算PHP多維數組的元素總數可以使用遞歸或迭代方法。 1.遞歸方法通過遍歷數組並遞歸處理嵌套數組來計數。 2.迭代方法使用棧來模擬遞歸,避免深度問題。 3.array_walk_recursive函數也能實現,但需手動計數。

在PHP中,do-while循環的特點是保證循環體至少執行一次,然後再根據條件決定是否繼續循環。 1)它在條件檢查之前執行循環體,適合需要確保操作至少執行一次的場景,如用戶輸入驗證和菜單系統。 2)然而,do-while循環的語法可能導致新手困惑,且可能增加不必要的性能開銷。

在PHP中高效地哈希字符串可以使用以下方法:1.使用md5函數進行快速哈希,但不適合密碼存儲。 2.使用sha256函數提高安全性。 3.使用password_hash函數處理密碼,提供最高安全性和便捷性。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

WebStorm Mac版
好用的JavaScript開發工具

Dreamweaver CS6
視覺化網頁開發工具

記事本++7.3.1
好用且免費的程式碼編輯器

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。