note 71485 modified in function.chmod by danbrown
| From: | danbrown@php.net | Date: | Thu, 16 Oct 2008 13:32:25 +0000 |
| Subject: | note 71485 modified in function.chmod by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145418@lists.php.net to get a copy of this message | ||
an update to 'neil at 11 out of 10's code for changing mode using FTP.
changes: proper array added within the function (better for those of us who only need to connect to
one ftp server) so only the mode and directory name need to be passed.
the octal added, for completeness and predictable stability.
<?php
function changemode($xcite)
{
$ftp_details = array(
ftp_user_name => 'username',
ftp_user_pass => 'password',
ftp_user_root => '/public_html/',
ftp_server => 'ftp.something.org'
);
$path = "public";
$mod = intval($xcite, 8);
// extract ftp details (array keys as variable names)
extract ($ftp_details);
// 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);
// try to chmod $path directory
if (ftp_site($conn_id, 'CHMOD '.$mod.' '.$ftp_root.$path) !== false) {
$success=TRUE;
}
else {
$success=FALSE;
}
// close the connection
ftp_close($conn_id);
return $success;
}
?>
for those of you, like me, who were looking for a way to make an 'un-hackable' uploader,
here's the closest i got, now for a field test, good luck!
--was--
an update to 'neil at 11 out of 10's code for changing mode using FTP.
changes: proper array added within the function (better for those of us who only need to connect to
one ftp server) so only the mode and directory name need to be passed.
the octal added, for completeness and predictable stability.
function changemode($xcite)
{
$ftp_details = array(
ftp_user_name => 'username',
ftp_user_pass => 'password',
ftp_user_root => '/public_html/',
ftp_server => 'ftp.something.org'
);
$path = "public";
$mod = intval($xcite, 8);
// extract ftp details (array keys as variable names)
extract ($ftp_details);
// 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);
// try to chmod $path directory
if (ftp_site($conn_id, 'CHMOD '.$mod.' '.$ftp_root.$path) !== false) {
$success=TRUE;
}
else {
$success=FALSE;
}
// close the connection
ftp_close($conn_id);
return $success;
}
then call it where required, an example:
changemode(777, directory);
if (@copy("$tempname", "$fullfilename")) $done = "yes";
changemode(755, directory);
for those of you, like me, who were looking for a way to make an 'un-hackable' uploader,
here's the closest i got, now for a field test, good luck!
http://php.net/manual/en/function.chmod.php