Code solutions to PHP, JS, CSSCode source PHP, JS, CSS

Spread your code soluces to the world

Love me
Solucior » PHP » Make dir and upload files via FTP

Make dir and upload files via FTP

05/19/2011 by Dux   -   5/5 (1 ratings)

These two functions simplify the creating directory and files upload by FTP in PHP.

source code



 
$ftp_host = 'ftp.server';
$ftp_user = 'root';
$ftp_pass = 'password';

// Make Dir
function mkdir_ftp($dir) {
       global
$ftp_host, $ftp_user, $ftp_pass;
       if (!
$conn = @ftp_connect($ftp_host)) return("FTP connection error");
       if (!
$login = @ftp_login($conn, $ftp_user, $ftp_pass)) return("Identification error");
       if (!@
ftp_mkdir($conn, $dir)) return("Creating directory error");
       
ftp_close($conn);
}

// Drop a file
function fput_ftp($distant, $local) {
       global
$ftp_host, $ftp_user, $ftp_pass;
       
$fp = fopen($local, 'r');
       if (!
$conn = @ftp_connect($ftp_host)) return("FTP connection error");
       if (!
$login_result = @ftp_login($conn, $ftp_user, $ftp_pass)) return("Identification error");
       if (!@
ftp_fput( $conn, $distant, $fp, FTP_BINARY )) return("Error creating file");
       
ftp_close($conn);
       
fclose($fp);
}
Rate this code     |     Copied : 18x

Comments for Make dir and upload files via FTP

No comment
Add a comment Nickname
ZOOM


Very simple drag and drop upload form
Create virtual folders using htaccess
Make dir and upload files via FTP
Simple method : listing files from a directory
Image class resize and rounded mask
Simple image gallery PHP