ocPortal Developer's Guide: Abstract file manager
» Return to Contents
The abstract file manager allows easy and transparent file system maintenance, even when it has to be piped through FTP.
sources/abstract_file_manager.php
Global_functions_abstract_file_manager.php
Function summary
|
void
|
init__abstract_file_manager ()
|
|
void
|
ftp_chmod (resource conn, integer access, PATH path)
|
|
void
|
force_have_afm_details ()
|
|
void
|
get_afm_form ()
|
|
tempcode
|
get_afm_form_fields ()
|
|
~resource
|
_ftp_info (boolean light_fail)
|
|
integer
|
_translate_dir_access (boolean world_access)
|
|
integer
|
_translate_file_access (boolean world_access, ID_TEXT file_type)
|
|
string
|
_access_string (integer access_int)
|
|
PATH
|
_rescope_path (PATH path)
|
|
void
|
afm_set_perms (PATH basic_path, boolean world_access)
|
|
void
|
afm_make_directory (PATH basic_path, boolean world_access, boolean recursive)
|
|
array
|
_get_dir_tree (PATH base, PATH at)
|
|
void
|
afm_delete_directory (PATH basic_path, boolean recursive)
|
|
void
|
afm_make_file (PATH basic_path, string contents, boolean world_access)
|
|
string
|
afm_read_file (PATH path)
|
|
void
|
afm_copy (PATH old_path, PATH new_path, boolean world_access)
|
|
void
|
afm_move (PATH basic_old_path, PATH basic_new_path)
|
|
void
|
afm_delete_file (PATH basic_path)
|
void init__abstract_file_manager()
Standard code module initialisation function.
Parameters…
(No return value)
function init__abstract_file_manager()
{
require_lang('abstract_file_manager');
require_lang('installer');
require_code('files');
global $AFM_FTP_CONN;
$AFM_FTP_CONN=NULL;
if (!function_exists('ftp_chmod')) // This was new in PHP5
{
/**
* FTP: Change a file's permissions.
*
* @param resource The FTP connection.
* @param integer The permissions desired.
* @param PATH The file path.
*/
function ftp_chmod($conn,$access,$path)
{
@ftp_site($conn,'CHMOD '._access_string($access).' '.$path);
}
}
}
void ftp_chmod(resource conn, integer access, PATH path)
FTP: Change a file's permissions.
Parameters…
| Name |
conn |
| Description |
The FTP connection. |
| Type |
resource |
| Name |
access |
| Description |
The permissions desired. |
| Type |
integer |
| Name |
path |
| Description |
The file path. |
| Type |
PATH |
(No return value)
function ftp_chmod($conn,$access,$path)
{
@ftp_site($conn,'CHMOD '._access_string($access).' '.$path);
}
void force_have_afm_details()
Make sure that the AFM connection details have been posted. If not, get them and loop back.
Parameters…
(No return value)
function force_have_afm_details()
{
if (is_suexec_like())
{
set_value('uses_ftp','0');
return; // No need for FTP
}
if (get_file_base()!=get_custom_file_base()) // Shared installs are assumed to have the necessary AFM permissions where needed
{
set_value('uses_ftp','0');
return;
}
if ((!function_exists('ftp_ssl_connect')) && (!function_exists('ftp_connect')))
{
set_value('uses_ftp','0');
return;
}
/*$ftp_domain=get_value('ftp_domain');
if (!is_null($ftp_domain))
{
$_POST['ftp_username']=get_value('ftp_username');
$_POST['ftp_directory']=get_value('ftp_directory');
$_POST['ftp_domain']=get_value('ftp_domain');
$_POST['uses_ftp']=get_value('uses_ftp');
// if ($_POST['uses_ftp']==0) return;
}*/
$got_ftp_details=post_param_integer('got_ftp_details',0);
$ftp_password=get_value('ftp_password');
if (is_null($ftp_password)) $ftp_password='';
//$uses_ftp=get_value('uses_ftp'); We can't use this because there's no reliable way to trust this is always going to be write (permissions change/differ, and we can't accurately run a test and trust the result going forward for everything)
if (/*($uses_ftp==='0') || */(strlen($ftp_password)>0)) // Permanently stored
{
return;
}
if ($got_ftp_details==0) // Get FTP details
{
get_afm_form();
} else
{
// Store them as values
$uses_ftp=post_param_integer('uses_ftp',0);
set_value('uses_ftp',strval($uses_ftp));
if ($uses_ftp==1)
{
set_value('ftp_username',post_param('ftp_username'));
$ftp_directory=post_param('ftp_directory');
if (substr($ftp_directory,0,1)!='/') $ftp_directory='/'.$ftp_directory;
set_value('ftp_directory',$ftp_directory);
set_value('ftp_domain',post_param('ftp_domain'));
if (post_param_integer('remember_password',0)==1)
set_value('ftp_password',post_param('ftp_password'));
}
}
}
void get_afm_form()
Force an AFM login.
Parameters…
(No return value)
function get_afm_form()
{
$fields=get_afm_form_fields();
$title=get_page_title('ABSTRACT_FILE_MANAGEMENT');
$post_url=get_self_url();
$submit_name=do_lang_tempcode('PROCEED');
$hidden=build_keep_post_fields();
$hidden->attach(form_input_hidden('got_ftp_details','1'));
if (ini_get('safe_mode')=='1')
{
$hidden->attach(form_input_hidden('uses_ftp','1'));
}
$javascript="var ftp_ticker=function() { var uses_ftp=document.getElementById('uses_ftp'); if (!uses_ftp) return; var form=uses_ftp.form; form.elements['ftp_domain'].disabled=!uses_ftp.checked; form.elements['ftp_directory'].disabled=!uses_ftp.checked; form.elements['ftp_username'].disabled=!uses_ftp.checked; form.elements['ftp_password'].disabled=!uses_ftp.checked; form.elements['remember_password'].disabled=!uses_ftp.checked; }; ftp_ticker(); document.getElementById('uses_ftp').onclick=ftp_ticker;";
@ob_end_clean();
$middle=do_template('FORM_SCREEN',array('_GUID'=>'c47a31fca47a7b22eeef3a6269cc2407','JAVASCRIPT'=>$javascript,'SKIP_VALIDATION'=>true,'HIDDEN'=>$hidden,'SUBMIT_NAME'=>$submit_name,'TITLE'=>$title,'FIELDS'=>$fields,'URL'=>$post_url,'TEXT'=>paragraph(do_lang_tempcode('TEXT_ABSTRACT_FILE_MANAGEMENT'))));
$echo=globalise($middle,NULL,'',true);
$echo->evaluate_echo();
exit();
}
tempcode get_afm_form_fields()
Get the fields that need to be filled in to know how to do an AFM connection.
Parameters…
Returns…
| Description |
The form fields. |
| Type |
tempcode |
function get_afm_form_fields()
{
require_code('form_templates');
$fields=new ocp_tempcode();
$ftp_username=get_value('ftp_username');
$ftp_directory=get_value('ftp_directory');
$ftp_domain=get_value('ftp_domain');
$_uses_ftp=running_script('upgrader')?'0':get_value('uses_ftp');
if (is_null($_uses_ftp))
{
$uses_ftp=!is_writable_wrap(get_file_base().'/adminzone/index.php');
} else
{
$uses_ftp=($_uses_ftp=='1');
}
// Domain
if (is_null($ftp_domain))
{
if (array_key_exists('ftp_domain',$GLOBALS['SITE_INFO']))
{
$ftp_domain=$GLOBALS['SITE_INFO']['ftp_domain'];
} else
{
$domain=ocp_srv('HTTP_HOST');
if (substr($domain,0,4)=='www.') $domain=substr($domain,4);
$colon_pos=strpos($domain,':');
if ($colon_pos!==false) $ftp_domain=substr($domain,0,$colon_pos); else $ftp_domain=$domain;
}
}
// Username
if (is_null($ftp_username))
{
if (array_key_exists('ftp_username',$GLOBALS['SITE_INFO']))
{
$ftp_username=$GLOBALS['SITE_INFO']['ftp_username'];
} else
{
if ((function_exists('posix_getpwuid')) && (strpos(@ini_get('disable_functions'),'posix_getpwuid')===false))
{
$u_info=posix_getpwuid(fileowner(get_file_base().'/index.php'));
if ($u_info!==false) $ftp_username=$u_info['name']; else $ftp_username='';
} else $ftp_username='';
if (is_null($ftp_username)) $ftp_username='';
}
}
// Directory
if (is_null($ftp_directory))
{
if (array_key_exists('ftp_directory',$GLOBALS['SITE_INFO']))
{
$ftp_directory=$GLOBALS['SITE_INFO']['ftp_directory'];
} else
{
$pos=strpos($_SERVER['PHP_SELF'],'adminzone/index.php');
if (($pos===false) && (get_zone_name()!='')) $pos=strpos($_SERVER['PHP_SELF'],get_zone_name().'/index.php');
if ($pos===false) $pos=strpos($_SERVER['PHP_SELF'],'data/');
if ($pos===false) $pos=strpos($_SERVER['PHP_SELF'],'data_custom/');
if ($pos===false) $pos=strpos($_SERVER['PHP_SELF'],'cms/index.php');
if ($pos===false) $pos=strpos($_SERVER['PHP_SELF'],'site/index.php');
$dr=array_key_exists('DOCUMENT_ROOT',$_SERVER)?$_SERVER['DOCUMENT_ROOT']:(array_key_exists('DOCUMENT_ROOT',$_ENV)?$_ENV['DOCUMENT_ROOT']:'');
if (strpos($dr,'/')!==false) $dr_parts=explode('/',$dr); else $dr_parts=explode('\\',$dr);
$webdir_stub=$dr_parts[count($dr_parts)-1];
$ftp_directory='/'.$webdir_stub.substr($_SERVER['PHP_SELF'],0,$pos);
}
}
$fields->attach(do_template('FORM_SCREEN_FIELD_SPACER',array('TITLE'=>do_lang_tempcode('SETTINGS'))));
if (ini_get('safe_mode')!='1')
{
$fields->attach(form_input_tick(do_lang_tempcode('NEED_FTP'),do_lang_tempcode('DESCRIPTION_NEED_FTP'),'uses_ftp',$uses_ftp));
}
$fields->attach(form_input_line(do_lang_tempcode('FTP_DOMAIN'),'','ftp_domain',$ftp_domain,false));
$fields->attach(form_input_line(do_lang_tempcode('FTP_DIRECTORY'),do_lang_tempcode('FTP_FOLDER'),'ftp_directory',$ftp_directory,false));
$fields->attach(form_input_line(do_lang_tempcode('FTP_USERNAME'),'','ftp_username',$ftp_username,false));
$fields->attach(form_input_password(do_lang_tempcode('FTP_PASSWORD'),'','ftp_password',false));
$fields->attach(do_template('FORM_SCREEN_FIELD_SPACER',array('TITLE'=>do_lang_tempcode('ACTIONS'))));
$fields->attach(form_input_tick(do_lang_tempcode('REMEMBER_PASSWORD'),do_lang_tempcode('DESCRIPTION_REMEMBER_PASSWORD'),'remember_password',false));
return $fields;
}
~resource _ftp_info(boolean light_fail)
Return the FTP connection, from stored/posted details.
Parameters…
| Name |
light_fail |
| Description |
Whether to simply echo-out errors. |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The FTP connection (false: not connecting via FTP). |
| Type |
~resource |
function _ftp_info($light_fail=false)
{
global $AFM_FTP_CONN;
if (!is_null($AFM_FTP_CONN)) return $AFM_FTP_CONN;
if (((get_value('uses_ftp')=='1') && (!running_script('upgrader'))) || (post_param_integer('uses_ftp',0)==1))
{
require_lang('installer');
$conn=false;
$domain=post_param('ftp_domain',get_value('ftp_domain'));
$port=21;
if (strpos($domain,':')!==false)
{
list($domain,$_port)=explode(':',$domain,2);
$port=intval($_port);
}
if (function_exists('ftp_ssl_connect')) $conn=@ftp_ssl_connect($domain,$port);
$ssl=($conn!==false);
$username=post_param('ftp_username',get_value('ftp_username'));
$password=post_param('ftp_password',get_value('ftp_password'));
if (($ssl) && (!@ftp_login($conn,$username,$password)))
{
$conn=false;
$ssl=false;
}
if (($conn===false) && (function_exists('ftp_connect'))) $conn=@ftp_connect($domain,$port);
if ($conn===false)
{
set_value('ftp_password','');
if ($light_fail)
{
$temp=do_lang_tempcode('NO_FTP_CONNECT');
echo '<strong>';
$temp->evaluate_echo();
echo '</strong>';
return;
} else
{
set_value('ftp_password',''); // Wipe out password, because we need the user to see FTP login screen again
attach_message(do_lang_tempcode('NO_FTP_CONNECT'),'warn');
get_afm_form();
}
}
$username=post_param('ftp_username',get_value('ftp_username'));
$password=post_param('ftp_password',get_value('ftp_password'));
if ((!$ssl) && (@ftp_login($conn,$username,$password)===false))
{
set_value('ftp_password','');
if ($light_fail)
{
$temp=do_lang_tempcode('NO_FTP_LOGIN',@strval($php_errormsg));
$temp->evaluate_echo();
return;
} else
{
set_value('ftp_password',''); // Wipe out password, because we need the user to see FTP login screen again
attach_message(do_lang_tempcode('NO_FTP_LOGIN',@strval($php_errormsg)),'warn');
get_afm_form();
}
}
$ftp_folder=post_param('ftp_folder',get_value('ftp_directory'));
if (substr($ftp_folder,-1)!='/') $ftp_folder.='/';
if (@ftp_chdir($conn,$ftp_folder)===false)
{
set_value('ftp_password','');
if ($light_fail)
{
$temp=do_lang_tempcode('NO_FTP_DIR',@strval($php_errormsg),'1');
$temp->evaluate_echo();
return;
} else
{
set_value('ftp_password',''); // Wipe out password, because we need the user to see FTP login screen again
attach_message(do_lang_tempcode('NO_FTP_DIR',@strval($php_errormsg),'1'),'warn');
get_afm_form();
}
}
$files=@ftp_nlist($conn,'.');
if ($files===false) // :(. Weird bug on some systems
{
$files=array();
if (@ftp_rename($conn,'info.php','info.php')) $files=array('info.php');
}
if (!in_array('info.php',$files))
{
set_value('ftp_password','');
if ($light_fail)
{
$temp=do_lang_tempcode('NO_FTP_DIR',@strval($php_errormsg),'2');
$temp->evaluate_echo();
return;
} else
{
set_value('ftp_password',''); // Wipe out password, because we need the user to see FTP login screen again
attach_message(do_lang_tempcode('NO_FTP_DIR',@strval($php_errormsg),'2'),'warn');
get_afm_form();
}
}
$AFM_FTP_CONN=$conn;;
return $AFM_FTP_CONN;
}
return false;
}
integer _translate_dir_access(boolean world_access)
Translate truth about needing world write access to a directory to absolute permissions.
Parameters…
| Name |
world_access |
| Description |
Whether world directory access is required. |
| Type |
boolean |
Returns…
| Description |
The absolute permission. |
| Type |
integer |
function _translate_dir_access($world_access)
{
if (is_suexec_like())
{
return 0755;
}
if (_ftp_info()===false) return 0777; // We want the FTP user to be able to delete.. otherwise it gets awkward for them
return $world_access?0777:0755;
}
integer _translate_file_access(boolean world_access, ID_TEXT file_type)
Translate truth about needing world write access to a file to absolute permissions.
Parameters…
| Name |
world_access |
| Description |
Whether world file access is required. |
| Type |
boolean |
| Name |
file_type |
| Description |
The file type (blank: don't care). |
| Default value |
|
| Type |
ID_TEXT |
Returns…
| Description |
The absolute permission. |
| Type |
integer |
function _translate_file_access($world_access,$file_type='')
{
$mask=0;
if ($file_type=='php')
{
$php_perms=fileperms(get_file_base().'/index.php');
if (($php_perms & 0100)==0100) // If PHP files need to be marked user executable
{
$mask=$mask | 0100;
}
if (($php_perms & 0010)==0010) // If PHP files need to be marked group executable
{
$mask=$mask | 0010;
}
if (($php_perms & 0001)==0001) // If PHP files need to be marked other executable
{
$mask=$mask | 0001;
}
}
if (is_suexec_like())
{
return 0644 | $mask;
}
if (_ftp_info()===false) return 0666 | $mask; // We want the FTP user to be able to delete.. otherwise it gets awkward for them
return ($world_access?0666:0644) | $mask;
}
string _access_string(integer access_int)
Convert an integer permission to the string version.
Parameters…
| Name |
access_int |
| Description |
The integer permission. |
| Type |
integer |
Returns…
| Description |
The string version. |
| Type |
string |
function _access_string($access_int)
{
return sprintf('%o',$access_int);
}
PATH _rescope_path(PATH path)
Rescope an ocPortal path to a path suitable for the AFM connection.
Parameters…
| Name |
path |
| Description |
Original path. |
| Type |
PATH |
Returns…
| Description |
Rescoped path. |
| Type |
PATH |
function _rescope_path($path)
{
if (post_param('uses_ftp',running_script('upgrader')?'0':get_value('uses_ftp'))=='1')
{
$ftp_folder=post_param('ftp_folder',get_value('ftp_directory'));
if (substr($ftp_folder,-1)!='/') $ftp_folder.='/';
return $ftp_folder.$path;
}
return get_custom_file_base().'/'.$path;
}
void afm_set_perms(PATH basic_path, boolean world_access)
Sets permissions over the open AFM connection.
Parameters…
| Name |
basic_path |
| Description |
The path of the file/directory we are setting permissions of. |
| Type |
PATH |
| Name |
world_access |
| Description |
Whether world access is required. |
| Type |
boolean |
(No return value)
function afm_set_perms($basic_path,$world_access)
{
$access=is_dir(get_file_base().'/'.$basic_path)?_translate_dir_access($world_access):_translate_file_access($world_access);
$path=_rescope_path($basic_path);
$conn=_ftp_info();
if ($conn!==false)
@ftp_chmod($conn,$access,$path);
else
@chmod($path,$access);
}
void afm_make_directory(PATH basic_path, boolean world_access, boolean recursive)
Make a directory over the open AFM connection.
Parameters…
| Name |
basic_path |
| Description |
The path to and of the directory we are making. |
| Type |
PATH |
| Name |
world_access |
| Description |
Whether world access is required. |
| Type |
boolean |
| Name |
recursive |
| Description |
Whether we should recursively make any directories that are missing in the given path, until we can make the final directory. |
| Default value |
boolean-false |
| Type |
boolean |
(No return value)
function afm_make_directory($basic_path,$world_access,$recursive=false)
{
$access=_translate_dir_access($world_access);
$path=_rescope_path($basic_path);
if ($recursive)
{
$parts=explode('/',$basic_path);
unset($parts[count($parts)-1]);
}
$conn=_ftp_info();
if ($conn!==false)
{
if ($recursive)
{
$build_up=post_param('ftp_folder',get_value('ftp_directory'));
foreach ($parts as $part)
{
$build_up.='/'.$part;
@ftp_mkdir($conn,$build_up);
@ftp_chmod($conn,$access,$build_up);
}
}
if (!file_exists(get_custom_file_base().'/'.$basic_path))
{
$success=@ftp_mkdir($conn,$path);
if (!is_string($success)) warn_exit(protect_from_escaping(@strval($php_errormsg)));
}
@ftp_chmod($conn,$access,$path);
clearstatcache();
sync_file(get_custom_file_base().'/'.$basic_path);
} else
{
if ($recursive)
{
$build_up=get_custom_file_base();
foreach ($parts as $part)
{
$build_up.='/'.$part;
@mkdir($build_up,$access); //0755
}
}
if (!file_exists(get_custom_file_base().'/'.$basic_path))
{
@mkdir($path,$access) OR warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY',escape_html($path),escape_html(dirname($path))));
} else
{
@chmod($path,$access);
}
sync_file($path);
}
}
array _get_dir_tree(PATH base, PATH at)
Get a list of files under a directory.
Parameters…
| Name |
base |
| Description |
The base directory for the search. |
| Type |
PATH |
| Name |
at |
| Description |
The directory where we are searching under. |
| Default value |
|
| Type |
PATH |
Returns…
| Description |
An array of directories found under this recursive level. |
| Type |
array |
function _get_dir_tree($base,$at='')
{
$out=array(array('dir',$at));
$stub=get_custom_file_base().'/'.$base.'/'.$at;
$dh=@opendir($stub);
if ($dh!==false)
{
while (($file=readdir($dh))!==false)
{
if (($file!='.') && ($file!='..'))
{
$stub2=$stub.(($at!='')?'/':'').$file;
if (is_dir($stub2))
{
$out=array_merge($out,_get_dir_tree($base,$at.(($at!='')?'/':'').$file));
} else
{
$out[]=array('file',$at.(($at!='')?'/':'').$file);
}
}
}
closedir($dh);
} else warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
return $out;
}
void afm_delete_directory(PATH basic_path, boolean recursive)
Delete a directory over the open AFM connection.
Parameters…
| Name |
basic_path |
| Description |
The path to and of the directory we are deleting. |
| Type |
PATH |
| Name |
recursive |
| Description |
Whether we should recursively delete any child files and directories. |
| Default value |
boolean-false |
| Type |
boolean |
(No return value)
function afm_delete_directory($basic_path,$recursive=false)
{
$paths=$recursive?array_reverse(_get_dir_tree($basic_path)):array(array('dir',''));
$conn=_ftp_info();
foreach ($paths as $bits)
{
list($type,$path)=$bits;
if ($type=='file')
{
afm_delete_file($basic_path.'/'.$path);
} else
{
$path=_rescope_path($basic_path.'/'.$path);
if ($conn!==false)
{
ftp_rmdir($conn,$path);
clearstatcache();
sync_file(get_custom_file_base().'/'.$basic_path);
} else
{
@rmdir($path) OR warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY',escape_html($path)));
sync_file($path);
}
}
}
}
void afm_make_file(PATH basic_path, string contents, boolean world_access)
Make a new file over the open AFM connection. Will overwrite if already exists (assuming has access).
Parameters…
| Name |
basic_path |
| Description |
The path to the file we are making. |
| Type |
PATH |
| Name |
contents |
| Description |
The desired file contents. |
| Type |
string |
| Name |
world_access |
| Description |
Whether world access is required. |
| Type |
boolean |
(No return value)
function afm_make_file($basic_path,$contents,$world_access)
{
$path=_rescope_path($basic_path);
$access=_translate_file_access($world_access,get_file_extension($basic_path));
$conn=_ftp_info();
if ($conn!==false)
{
$path2=ocp_tempnam('ocpafm');
$h=fopen($path2,'wb');
if (fwrite($h,$contents)<strlen($contents)) warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE_TMP',escape_html($path2)));
fclose($h);
$h=fopen($path2,'rb');
$success=@ftp_fput($conn,$path,$h,FTP_BINARY);
if (!$success)
{
if (running_script('upgrader'))
{
echo @strval($php_errormsg);
return;
}
warn_exit(protect_from_escaping(@strval($php_errormsg)));
}
fclose($h);
unlink($path2);
@ftp_chmod($conn,$access,$path);
clearstatcache();
sync_file(get_custom_file_base().'/'.$basic_path);
} else
{
$h=@fopen($path,'wb');
if ($h===false) intelligent_write_error($path);
if (fwrite($h,$contents)<strlen($contents)) warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE_TMP'));
fclose($h);
@chmod($path,$access);
fix_permissions($path);
sync_file($path);
}
}
string afm_read_file(PATH path)
Read a file (not actually over the open AFM connection, but same result: we can do this directly).
Parameters…
| Name |
path |
| Description |
The path to the file we are reading. |
| Type |
PATH |
Returns…
| Description |
The contents of the file. |
| Type |
string |
function afm_read_file($path)
{
return file_get_contents(get_custom_file_base().'/'.$path);
}
void afm_copy(PATH old_path, PATH new_path, boolean world_access)
Copies a file (NOT a directory) on the open AFM connection.
Parameters…
| Name |
old_path |
| Description |
The path to the file we are copying. |
| Type |
PATH |
| Name |
new_path |
| Description |
The target path. |
| Type |
PATH |
| Name |
world_access |
| Description |
Whether world access is required for the copy. |
| Type |
boolean |
(No return value)
function afm_copy($old_path,$new_path,$world_access)
{
$a=get_custom_file_base().'/'.$old_path;
if (!file_exists($a)) $a=get_file_base().'/'.$old_path;
$contents=file_get_contents($a);
afm_make_file($new_path,$contents,$world_access);
}
void afm_move(PATH basic_old_path, PATH basic_new_path)
Moves a file on the open AFM connection.
Parameters…
| Name |
basic_old_path |
| Description |
The path to the file we are moving from. |
| Type |
PATH |
| Name |
basic_new_path |
| Description |
The target path. |
| Type |
PATH |
(No return value)
function afm_move($basic_old_path,$basic_new_path)
{
if (is_dir(get_custom_file_base().'/'.$basic_new_path)) $basic_new_path.=substr($basic_old_path,strrpos($basic_old_path,'/')); // If we are moving to a path, add on the filename to that path
$old_path=_rescope_path($basic_old_path);
$new_path=_rescope_path($basic_new_path);
$conn=_ftp_info();
if ($conn!==false)
{
$success=@ftp_rename($conn,$old_path,$new_path);
if (!$success)
{
if (running_script('upgrader'))
{
echo @strval($php_errormsg);
return;
}
warn_exit(protect_from_escaping(@strval($php_errormsg)));
}
clearstatcache();
sync_file_move(get_custom_file_base().'/'.$basic_old_path,get_custom_file_base().'/'.$basic_new_path);
} else
{
rename($old_path,$new_path);
sync_file_move($old_path,$new_path);
}
}
void afm_delete_file(PATH basic_path)
Deletes a file (NOT a directory) on the open AFM connection.
Parameters…
| Name |
basic_path |
| Description |
The path to the file we are deleting. |
| Type |
PATH |
(No return value)
function afm_delete_file($basic_path)
{
$path=_rescope_path($basic_path);
$conn=_ftp_info();
if ($conn!==false)
{
$success=@ftp_delete($conn,$path);
if (!$success)
{
if (running_script('upgrader'))
{
echo @strval($php_errormsg);
return;
}
warn_exit(protect_from_escaping(@strval($php_errormsg)));
}
clearstatcache();
sync_file(get_custom_file_base().'/'.$basic_path);
} else
{
if (!file_exists($path)) return;
@unlink($path) OR intelligent_write_error($path);
sync_file($path);
}
}
0 reviews: Unrated (average)
There have been no comments yet