How to use PHP to support FTP and HTTP uploads? in the process of learning programming, I think it is not only necessary to acquire the textbook knowledge, but also a solution to the problem, in the face of the new problem how to solve, so that we can walk in the forefront, I am a student of Dana, this article is reproduced in (http://www.phptarena.com) Thank you for your support; how to use PH to support FTP and HTTP uploads through PHP
In the process of learning programming, I think that we should not only acquire the knowledge of textbooks, but also solve problems and how to solve new problems so that we can stay at the forefront, I am a student of Dana, this article is reproduced in (http://www.phptarena.com) Thank you for your support;
With PHP, you can always complete a specific task in multiple ways. Let's take File upload as an example. Of course, you can use the traditional method to upload HTTP files and directly transfer the files to the Web server disk. You can also upload files in a more exotic way, using the FTP protocol in two steps: from your local hard disk to the Web server, and then to the FTP server.
PHP supports both FTP and HTTP uploads on the local machine, so you can make the best choice according to your application design needs. Using the FTP function of PHP for file transfer is almost the same as using the traditional FTP client-you will see that the name of the function is similar to the standard FTP command.
There are already many articles about HTTP file upload, which is why it is necessary to focus on FTP-based file upload (but in the example below, ). Note that this tutorial assumes that you have installed PHP/Apache and the HTTP File upload and FTP functions are activated.
Step 1: Make sure you have the permission to connect to/upload to the FTP server
Php ftp functions require client-server connection, so you need to log on to the target server before uploading files. Your first task is to make sure that you have the trust book to complete this task. This step may seem to be taken for granted, but you will be surprised to find how many developers have forgotten to do so. as a result, they will waste a lot of time to solve the problem.
You can log on to the target server by using the FTP client of the command line to check the connection status and try to upload a false file.
Once you confirm that you have the relevant access permissions, you can log in.
Step 2: Create an upload form
Then, create a simple HTML form and ask the user about the access information of the FTP server, the directory uploaded by the server, The Complete Directory and the name of the uploaded file. The following example shows the form style.
Here, Element is used to generate a file selection dialog box. you can use it to select the file to be uploaded. The element then encodes the form data into multiple parts for submission, which makes it easier for PHP to identify submitted file components.
Step 3: Create a PHP Upload handler
Once the form is submitted to the Web server, the next step (and the last step) is to use the FTP function of PHP to transmit it to the target server according to the user-provided access trust book. The following is the script (upload. php) that completes all the above work ).
Knowledge is power. it is a low cost for others to learn to make money by using knowledge. programming in Dana is a place to create a dream. if you like programming, here we share a common language and story, A common dream!
(Responsible editor: Guangzhou Dana)
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