Table of Contents
PHP implementation of ftp file upload example, _PHP tutorial
Jul 13, 2016 am 10:20 AM
ftp
php
Example of PHP implementation of ftp upload file,
FTP upload is a common and very important application skill implemented in PHP. Today I will share with you a simple example of FTP uploading files in PHP. I hope it will be of some help to everyone's PHP learning.
The main code is as follows:
function make_directory($ftp_stream, $dir){ // if directory already exists or can be immediately created return true if ($this->ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true; // otherwise recursively try to make the directory if (!$this->make_directory($ftp_stream, dirname($dir))) return false; // final step to create the directory return ftp_mkdir($ftp_stream, $dir); } function ftp_is_dir($ftp_stream, $dir){ // get current directory $original_directory = ftp_pwd($ftp_stream); // test if you can change directory to $dir // suppress errors in case $dir is not a file or not a directory if ( @ftp_chdir( $ftp_stream, $dir ) ) { // If it is a directory, then change the directory back to the original directory ftp_chdir( $ftp_stream, $original_directory ); return true; } else { return false; } } $conn = ftp_connect("ftp地址") or die("Could not connect"); ftp_login($conn,"ftpname","password"); //利用ftp创建目录 make_directory($conn,$path); //利用ftp选择进入目录 ftp_chdir($conn,$path); //开始上传 if(ftp_put($conn,$info[0]['savename'],getcwd().$upload->savePath.$info[0]['savename'],FTP_BINARY)){ unlink(getcwd().$upload->savePath.$info[0]['savename']); } ftp_close($conn); //注意上传端的ftp权限设置
Copy after login
Interested friends can test run or rewrite the code described in this article to deepen their understanding and improve the function of the code.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

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

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
