note 69267 added to function.mkdir
| From: | LarsPätzold at osu1 dot php dot net | Date: | Tue, 29 Aug 2006 12:44:04 +0000 |
| Subject: | note 69267 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116467@lists.php.net to get a copy of this message | ||
Just a small addition to Han Van den Hoof's ftp script which is really useful for scripts on
shared servers.
I added a chmod command. This is necessary if you want to access the directory later via script.
I also fixed the small bug with the 2 variables connection & conn_id ;)
And last not least ftp connection is closed even if ftp commands fail.
Sometimes ftp login will fail due to bad luck. Therefore one should add a loop for retrying.
<?php
// create directory through FTP connection
function FtpMkdir($path, $newDir) {
$server='ftp.yourserver.com'; // ftp server
$connection = ftp_connect($server); // connection
// login to ftp server
$user = "me";
$pass = "password";
$result = ftp_login($connection, $user, $pass);
// check if connection was made
if ((!$connection) || (!$result)) {
return false;
exit();
} else {
if (!ftp_chdir($connection, $path)) { // go to destination dir
$r = false;
} else if (!ftp_mkdir($connection,$newDir)) { // create directory
$r = false;
} else if (!ftp_site($connection, "CHMOD 0777 $newDir") { // change attributes
$r = false;
} else {
$r = $newDir;
}
}
ftp_close($connection); // close connection
return $r;
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 129.13.186.1 (proxied: 172.20.69.18)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mkdir.php
Edit -- https://master.php.net/note/edit/69267
Del: integrated -- https://master.php.net/note/delete/69267/integrated
Del: useless -- https://master.php.net/note/delete/69267/useless
Del: bad code -- https://master.php.net/note/delete/69267/bad+code
Del: spam -- https://master.php.net/note/delete/69267/spam
Del: non-english -- https://master.php.net/note/delete/69267/non-english
Del: in docs -- https://master.php.net/note/delete/69267/in+docs
Del: other reasons-- https://master.php.net/note/delete/69267
Reject -- https://master.php.net/note/reject/69267
Search -- https://master.php.net/manage/user-notes.php