用PHP实现文件上传二法
上传
PHP(Hypertext Preprocessor)是一种 HTML 内嵌式的语言 (类似 IIS 上的ASP)。而 PHP 独特的语法混合了 C、Java、Perl 以及 PHP 式的新语法。它可以比 CGI 或者 Perl 更快速的执行动态网页。除此之外,用 PHP 写出来的 Web 后端CGI 程序,可以很轻易的移植到不同的系统平台上。
我们在做网站时,需要访问者的参于才能将网站建设得更加引人注目,这就要求我们从访问者那里得到文章、图片等。因此,文件上传成为网页中必不可少的功能。现在我就利用现在流行的编程语言PHP,用两种方法来说明其功能的实现。
一、利用php的文件函数来实现上传
这段代码分为两个文件,一个为upload.html,一个是upload.php。
上传文件选择:upload.html 代码如下:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
*** 说明 ***
1、请注意
--------------------------------------------------------------------------------
处理上传文件:ftp.php 代码如下:
--------------------------------------------------------------------------------
//ftp联接主机函数
function connect()
{
global $server, $username, $password;
$conn = ftp_connect($server);
ftp_login($conn, $username, $password);
return $conn;
}
//建立ftp联接
$result = connect();
if ($action == "上传")
{
//用来改变ftp路径
ftp_chdir($result, $cdir);
//用来上传指定的文件,同名并以二进制位传递
$res_code = ftp_put($result, $upfile_name, $upfile, FTP_BINARY);
// 判断是否正确上传
if ($res_code == 1)
echo "上传成功!";
else
echo "上传错误!";
}
// 关闭联接
ftp_quit($result);
?>
--------------------------------------------------------------------------------
*** 说明 ***
函数ftp_put(int ftp_stream, string remote_file, string local_file, int mode)用法
返回值: 布尔值
本函数用来上传指定的文件。参数 ftp_stream 为 FTP 的连接代码。参数 remote_file 为欲存在远端的文件名。参数 local_file 为欲上传文件的文件名。参数 mode 的值有 FTP_ASCII 及 FTP_BINARY 二种,分别表示文档或者是二进位文件。成功则返回 true 值,失败则返回 false 值。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

1. Install nginx 2. Install vsftpd 3. Modify the nginx configuration file nginx.conf 3.1 Add the ftp user userftpuser in the first line; 3.2 Configure the relevant path server{ listen80; #nginx proxy port server_namelocalhost; #ftp server address location/images{root /home/ftpuser; #The absolute path of the folder of the proxy ftp server indexftpuser; #Set the welcome page

With the rapid development of the Internet, File Transfer Protocol (FTP) has always been an important file transfer method. In Go language, using FTP to transfer files may be a need of many developers. However, maybe many people don't know how to use FTP in Go language. In this article, we will explore how to use FTP in Go language, from connecting to FTP server to file transfer, and how to handle errors and exceptions. Create FTP connection In Go language, we can use the standard "net" package to connect to FTP

PHP and FTP: Achieve file sharing among multiple departments in website development. With the development of the Internet, more and more companies are beginning to use website platforms for information release and business promotion. However, the problem that arises is how to achieve file sharing and collaboration among multiple departments. In this case, PHP and FTP become one of the most commonly used solutions. This article will introduce how to use PHP and FTP to achieve file sharing among multiple departments in website development. 1. Introduction to FTP FTP (FileTransferPr

The ftp commands under Linux include: 1. ftp command; 2. close command; 3. disconnect command; 4. open command; 5. user command; 6. account command; 7. bye command; 8. quit command; 9. help command ;10. rhelp command; 11. ascii command; 12. binary/bi command; 13. bell command, etc.

How to compare directories and files on an FTP server through PHP In web development, sometimes we need to compare local files with files on the FTP server to ensure consistency between the two. PHP provides some functions and classes to implement this functionality. This article will introduce how to use PHP to compare directories and files on an FTP server, and provide relevant code examples. First, we need to connect to the FTP server. PHP provides the ftp_connect() function to establish an FTP server

1. Environment: ftp is vsftp. The username is set to test. The restricted path is /home/test2. Create a user: under the root user: useradd-d/home/testtest#Add user test, and set the home directory of the test user to /home/testpasswdtest#Set a password for the test user3. Change the corresponding permission settings of the user: 1.usermod-s/sbin/nologintest#Limit user test cannot telnet, only ftp2.usermod-s/bin/bashtest#Return to normal for user test 3.usermod-d

linux ftp530 means linux ftp login error 530. The solution is: 1. Check "cat /etc/shells" to see if your user's home directory and login shell are there. If not, add them; 2. Check "/var /log/secure" file and reset the password expiration time.
