PHP script upload FTP on multiple websites?

PHP script upload FTP on multiple websites?

The script has two files, one for uploading the file via FTP and the php code file.

The idea is that in order to upload a file to multiple websites, you need to duplicate the code (copy/paste) and just modify the credentials, db username, db password and the name of the website (FTP server name).


Don’t make the mistake of writing the sql connection code. You only need the FTP credentials. If you write the SQL connection, you will get an error like: “Warning: ftp_put(): 1 is not a valid FTP Buffer resource on line..”.

$paths = ‘/public_html/’; if you want to upload your file into the root of your website. Modify $paths = ‘/public_html/images/’; if you want to upload the file into your “images” folder.

Duplicate the code from upl_test.php as many times as you want, depending on how many websites you want to upload your file.

Notice that when you upload, you need to leave upl_test.php for a few minutes to finish the uploading process (depending on the size of your file).

This is the code from upl_test.php

Download both files from here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$ftp_server = 'website.com';
$ftp_user_name = 'enter_sql_username';
$ftp_user_pass = 'enter_sql_pass';
 
// set up basic connection
$conn_id = ftp_connect($ftp_server);
 
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
 
$filep=$_FILES['userfile']['tmp_name'];
$name=$_FILES['userfile']['name'];
$paths = '/public_html/';
 
$upload = ftp_put($conn_id, $paths.'/'.$name, $filep, FTP_BINARY);
 
// close the connection
ftp_close($conn_id);
?>

Add a comment: