コード例 #1
0
 /**
  * Copies a file. Mostly a wrapper of WP_Filesystem::copy
  * @param string $source_file
  * @param string $destination_file
  * @param boolean $overwrite
  * @throws EE_Error if filesystem credentials are required
  * @return boolean success
  */
 public static function copy($source_file, $destination_file, $overwrite = FALSE)
 {
     $full_source_path = EEH_File::standardise_directory_separators($source_file);
     if (!EEH_File::exists($full_source_path)) {
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
             $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
             throw new EE_Error($msg);
         }
         return FALSE;
     }
     $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
     $folder = EEH_File::remove_filename_from_filepath($full_dest_path);
     if (!EEH_File::verify_is_writable($folder, 'folder')) {
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
             $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
             throw new EE_Error($msg);
         }
         return FALSE;
     }
     // load WP_Filesystem and set file permissions
     $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
     // write the file
     if (!$wp_filesystem->copy(EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), $overwrite)) {
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
             $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
             throw new EE_Error($msg);
         }
         return FALSE;
     }
     return TRUE;
 }