Tuesday, April 15, 2008

Use Ftp To Make New Folders

Few months ago I had a problem of creating folders using php script, but with this link, the problem had been solved.

function FtpMkdir($path, $newDir) {

$server='.....'; // ftp server
$connection = ftp_connect($server); // connection

// login to ftp server
$user = "........";
$pass = "******";

$result = ftp_login($connection, $user, $pass);

// check if connection was made
if ((!$connection) || (!$result)) {
return false;
exit();
} else {
ftp_chdir($connection, $path); // go to destination dir

if(ftp_mkdir($connection, $newDir)) { // create directory
ftp_site($connection, "CHMOD 777 $path/$newDir") or die("FTP SITE CMD failed.");
return $newDir;
} else {
return false;
}

ftp_close($connection); // close connection
}
}