By Vikram Vaswani
Melonfire
November 07, 2000
Now, we have come into contact with a large number of functions related to FTP in PHP, but these are just functions and are far from our goal. To show the real power of these functions, we should Create a program that can upload and download files via WEB --- this is what we will do!
Before we get into the code, what I want to tell you is that this example is just to explain the use of various FTP functions of PHP. It is not perfect in many aspects, such as error analysis, etc. As for what you want to apply it to In your own program, you should make some modifications!
The program includes the following files:
index.html - login file
actions.php - FTP code necessary for the program
include.php - the main interface of the program, which displays the file list and control buttons.
Let’s start with "index.html":
---------------------------------------- ---------------------------------------------
---------------- -------------------------------------------------- -------------
This is a login form with a server name, username, password, and input box. The entered variables will be stored in the $server, $username and $password variables. After the form is submitted, actions.php is called, which will initialize the FTP connection.
Pay attention to the "hidden" which passes a variable $action to action.php with the value CWD.
This is the source code of the action.php file:
--------------------------------------------- -------------------------------------
//Check form If the transmitted data is incomplete, an error will be reported. If you want the program to be perfect, there should be a more complete input detection function here
if (!$server || !$username || !$password)
{
echo "The submitted data is incomplete! ";
}
else
{
// keep reading
}
?>
----------------- -------------------------------------------------- ------------
Next is the variable "actions". The program allows the following actions:
"action=CWD"
Change the working directory
"action=Delete"
Delete the specified file
"action =Download"
Download the specified file
"action=Upload"
Upload the specified file
If you carefully examine the file include.php, which contains an HTML interface, you will see that it includes many forms, each pointing to a specific Function, each form contains a field (usually hidden), when the form is submitted, the corresponding function will be executed.
For example: when "Delete" is pressed, "action=Delete" is sent to "actions.php"
In order to operate these four functions, the code in actions.php is as follows:
---------- -------------------------------------------------- -------------------
// action: change directory
if ($action == "CWD")
{
// specific code
}
// action: Delete file
else if ($action == "Delete")
{
// Specific code
}
// action: Download file
else if ($action == "Download")
{
// Specific code
}
// action: Upload file
else if ($action == "Upload")
{
// Specific code
}
?>
---------- -------------------------------------------------- -------------------
The above specific codes will implement the specified functions and exit the loop. They all include the following steps:
-------- -------------------------------------------------- -----------------------
Connect and log in to the FTP server through a customized function
connect();
Shift to the appropriate directory
Perform the selected function
Refresh the list , to see the result of the change
Display the file list and control buttons through include("include.php")
Close the connection
----------------------- -------------------------------------------------- -------
Note:
The following functions support multi-file operations - namely "action=Delete" and "action=Download" which are implemented using FOR loops.
Variables $cdir and $here will be updated in real time at each stage.
Now we finally get to our third file, include.php which sets up a user interface for the program.
"include.php" contains three forms, some PHP code to get the current directory list and store them into three variables
$files (including files in the current directory),
$file_sizes (corresponding file sizes),
and $dirs (contains subdirectory names)
The first form uses $dirs to generate a drop-down directory list, corresponding to "action=CWD".
The second form uses $files $file_sizes to create a list of available files, and each file uses a checkbox. The action of this form corresponds to "action=Delete" and "action=Download"
The third form is used to upload a file to the FTP site, as follows:
---------------- -------------------------------------------------- --------------
----------------------------------------- ------------------------------------------
When PHP receives this way When a file name is given, some variables are generated. These variables specify the file size, a temporary file name and the file type. The initial file name is stored in $upfile_name. Once uploaded, the file name is stored in $upfile (this variable is created by PHP itself)
With this information, we can create the following statement:
---------------------------- -------------------------------------------------- --
ftp_put($result, $upfile_name, $upfile, FTP_BINARY);
-------------------------------- ---------------------------------------------
The above introduces PHP FTP learning three, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

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

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

DJI has not confirmed any plans to introduce a new action camera yet. Instead, it seems that GoPro will get ahead of its rival this year, having teased that it will introduce two new action cameras on September 4. For context, these are expected to a

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

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

第1部分:初始故障排除步骤检查苹果的系统状态:在深入研究复杂的解决方案之前,让我们从基础知识开始。问题可能不在于您的设备;苹果的服务器可能会关闭。访问Apple的系统状态页面,查看AppStore是否正常工作。如果有问题,您所能做的就是等待Apple修复它。检查您的互联网连接:确保您拥有稳定的互联网连接,因为“无法连接到AppStore”问题有时可归因于连接不良。尝试在Wi-Fi和移动数据之间切换或重置网络设置(“常规”>“重置”>“重置网络设置”>设置)。更新您的iOS版本:

转化方法:1、使用“mb_substr($url,stripos($url,"?")+1)”获取url的参数部分;2、使用“parse_str("参数部分",$arr)”将参数解析到变量中,并传入指定数组中,变量名转为键名,变量值转为键值。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
