PHP implementation FTP upload file Sample _php tips

Source: Internet
Author: User
Tags ftp upload file

FTP upload is a common and very important implementation of PHP application techniques, today to share with you the PHP implementation of FTP upload file simple example. We hope that the study of PHP can bring some help.

The main code is as follows:

function Make_directory ($ftp _stream, $dir) {//If directory already exists or can is 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 FAL
  Se
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 isn't a file or not a directory if (@ftp
    _chdir ($ftp _stream, $dir)) {//If It's 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 address") or die ("could not Connect");
Ftp_login ($conn, "Ftpname", "password"); Create a directory Make_dir with FTPEctory ($conn, $path);
Use FTP to select access to directory Ftp_chdir ($conn, $path);
 Start uploading if (Ftp_put ($conn, $info [0][' Savename '],getcwd (). $upload->savepath. $info [0][' savename]) {
Unlink (GETCWD (). $upload->savepath. $info [0][' Savename ']);
} ftp_close ($conn);

 Note The FTP permission settings on the upload side

Interested friends can test run or rewrite the code described in this article, and deepen your understanding while making the code more functional.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.