webmaster@1: TRUE));
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Make sure the destination is a complete path and resides in the file system
webmaster@1: * directory, if it is not prepend the file system directory.
webmaster@1: *
webmaster@1: * @param $dest A string containing the path to verify. If this value is
webmaster@1: * omitted, Drupal's 'files' directory will be used.
webmaster@1: * @return A string containing the path to file, with file system directory
webmaster@1: * appended if necessary, or FALSE if the path is invalid (i.e. outside the
webmaster@1: * configured 'files' or temp directories).
webmaster@1: */
webmaster@1: function file_create_path($dest = 0) {
webmaster@1: $file_path = file_directory_path();
webmaster@1: if (!$dest) {
webmaster@1: return $file_path;
webmaster@1: }
webmaster@1: // file_check_location() checks whether the destination is inside the Drupal files directory.
webmaster@1: if (file_check_location($dest, $file_path)) {
webmaster@1: return $dest;
webmaster@1: }
webmaster@1: // check if the destination is instead inside the Drupal temporary files directory.
webmaster@1: else if (file_check_location($dest, file_directory_temp())) {
webmaster@1: return $dest;
webmaster@1: }
webmaster@1: // Not found, try again with prefixed directory path.
webmaster@1: else if (file_check_location($file_path .'/'. $dest, $file_path)) {
webmaster@1: return $file_path .'/'. $dest;
webmaster@1: }
webmaster@1: // File not found.
webmaster@1: return FALSE;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Check that the directory exists and is writable. Directories need to
webmaster@1: * have execute permissions to be considered a directory by FTP servers, etc.
webmaster@1: *
webmaster@1: * @param $directory A string containing the name of a directory path.
webmaster@1: * @param $mode A Boolean value to indicate if the directory should be created
webmaster@1: * if it does not exist or made writable if it is read-only.
webmaster@1: * @param $form_item An optional string containing the name of a form item that
webmaster@1: * any errors will be attached to. This is useful for settings forms that
webmaster@1: * require the user to specify a writable directory. If it can't be made to
webmaster@1: * work, a form error will be set preventing them from saving the settings.
webmaster@1: * @return FALSE when directory not found, or TRUE when directory exists.
webmaster@1: */
webmaster@1: function file_check_directory(&$directory, $mode = 0, $form_item = NULL) {
webmaster@1: $directory = rtrim($directory, '/\\');
webmaster@1:
webmaster@1: // Check if directory exists.
webmaster@1: if (!is_dir($directory)) {
webmaster@1: if (($mode & FILE_CREATE_DIRECTORY) && @mkdir($directory)) {
webmaster@1: drupal_set_message(t('The directory %directory has been created.', array('%directory' => $directory)));
webmaster@1: @chmod($directory, 0775); // Necessary for non-webserver users.
webmaster@1: }
webmaster@1: else {
webmaster@1: if ($form_item) {
webmaster@1: form_set_error($form_item, t('The directory %directory does not exist.', array('%directory' => $directory)));
webmaster@1: }
webmaster@1: return FALSE;
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: // Check to see if the directory is writable.
webmaster@1: if (!is_writable($directory)) {
webmaster@1: if (($mode & FILE_MODIFY_PERMISSIONS) && @chmod($directory, 0775)) {
webmaster@1: drupal_set_message(t('The permissions of directory %directory have been changed to make it writable.', array('%directory' => $directory)));
webmaster@1: }
webmaster@1: else {
webmaster@1: form_set_error($form_item, t('The directory %directory is not writable', array('%directory' => $directory)));
webmaster@1: watchdog('file system', 'The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => $directory), WATCHDOG_ERROR);
webmaster@1: return FALSE;
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: if ((file_directory_path() == $directory || file_directory_temp() == $directory) && !is_file("$directory/.htaccess")) {
webmaster@1: $htaccess_lines = "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks";
webmaster@1: if (($fp = fopen("$directory/.htaccess", 'w')) && fputs($fp, $htaccess_lines)) {
webmaster@1: fclose($fp);
webmaster@1: chmod($directory .'/.htaccess', 0664);
webmaster@1: }
webmaster@1: else {
webmaster@1: $variables = array('%directory' => $directory, '!htaccess' => '
'. nl2br(check_plain($htaccess_lines)));
webmaster@1: form_set_error($form_item, t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: !htaccess
", $variables));
webmaster@1: watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: !htaccess
", $variables, WATCHDOG_ERROR);
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: return TRUE;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Checks path to see if it is a directory, or a dir/file.
webmaster@1: *
webmaster@1: * @param $path A string containing a file path. This will be set to the
webmaster@1: * directory's path.
webmaster@1: * @return If the directory is not in a Drupal writable directory, FALSE is
webmaster@1: * returned. Otherwise, the base name of the path is returned.
webmaster@1: */
webmaster@1: function file_check_path(&$path) {
webmaster@1: // Check if path is a directory.
webmaster@1: if (file_check_directory($path)) {
webmaster@1: return '';
webmaster@1: }
webmaster@1:
webmaster@1: // Check if path is a possible dir/file.
webmaster@1: $filename = basename($path);
webmaster@1: $path = dirname($path);
webmaster@1: if (file_check_directory($path)) {
webmaster@1: return $filename;
webmaster@1: }
webmaster@1:
webmaster@1: return FALSE;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Check if a file is really located inside $directory. Should be used to make
webmaster@1: * sure a file specified is really located within the directory to prevent
webmaster@1: * exploits.
webmaster@1: *
webmaster@1: * @code
webmaster@1: * // Returns FALSE:
webmaster@1: * file_check_location('/www/example.com/files/../../../etc/passwd', '/www/example.com/files');
webmaster@1: * @endcode
webmaster@1: *
webmaster@1: * @param $source A string set to the file to check.
webmaster@1: * @param $directory A string where the file should be located.
webmaster@1: * @return 0 for invalid path or the real path of the source.
webmaster@1: */
webmaster@1: function file_check_location($source, $directory = '') {
webmaster@1: $check = realpath($source);
webmaster@1: if ($check) {
webmaster@1: $source = $check;
webmaster@1: }
webmaster@1: else {
webmaster@1: // This file does not yet exist
webmaster@1: $source = realpath(dirname($source)) .'/'. basename($source);
webmaster@1: }
webmaster@1: $directory = realpath($directory);
webmaster@1: if ($directory && strpos($source, $directory) !== 0) {
webmaster@1: return 0;
webmaster@1: }
webmaster@1: return $source;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Copies a file to a new location. This is a powerful function that in many ways
webmaster@1: * performs like an advanced version of copy().
webmaster@1: * - Checks if $source and $dest are valid and readable/writable.
webmaster@1: * - Performs a file copy if $source is not equal to $dest.
webmaster@1: * - If file already exists in $dest either the call will error out, replace the
webmaster@1: * file or rename the file based on the $replace parameter.
webmaster@1: *
webmaster@1: * @param $source A string specifying the file location of the original file.
webmaster@1: * This parameter will contain the resulting destination filename in case of
webmaster@1: * success.
webmaster@1: * @param $dest A string containing the directory $source should be copied to.
webmaster@1: * If this value is omitted, Drupal's 'files' directory will be used.
webmaster@1: * @param $replace Replace behavior when the destination file already exists.
webmaster@1: * - FILE_EXISTS_REPLACE - Replace the existing file
webmaster@1: * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
webmaster@1: * - FILE_EXISTS_ERROR - Do nothing and return FALSE.
webmaster@1: * @return True for success, FALSE for failure.
webmaster@1: */
webmaster@1: function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
webmaster@1: $dest = file_create_path($dest);
webmaster@1:
webmaster@1: $directory = $dest;
webmaster@1: $basename = file_check_path($directory);
webmaster@1:
webmaster@1: // Make sure we at least have a valid directory.
webmaster@1: if ($basename === FALSE) {
webmaster@1: $source = is_object($source) ? $source->filepath : $source;
webmaster@1: drupal_set_message(t('The selected file %file could not be uploaded, because the destination %directory is not properly configured.', array('%file' => $source, '%directory' => $dest)), 'error');
webmaster@1: watchdog('file system', 'The selected file %file could not be uploaded, because the destination %directory could not be found, or because its permissions do not allow the file to be written.', array('%file' => $source, '%directory' => $dest), WATCHDOG_ERROR);
webmaster@1: return 0;
webmaster@1: }
webmaster@1:
webmaster@1: // Process a file upload object.
webmaster@1: if (is_object($source)) {
webmaster@1: $file = $source;
webmaster@1: $source = $file->filepath;
webmaster@1: if (!$basename) {
webmaster@1: $basename = $file->filename;
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: $source = realpath($source);
webmaster@1: if (!file_exists($source)) {
webmaster@1: drupal_set_message(t('The selected file %file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $source)), 'error');
webmaster@1: return 0;
webmaster@1: }
webmaster@1:
webmaster@1: // If the destination file is not specified then use the filename of the source file.
webmaster@1: $basename = $basename ? $basename : basename($source);
webmaster@1: $dest = $directory .'/'. $basename;
webmaster@1:
webmaster@1: // Make sure source and destination filenames are not the same, makes no sense
webmaster@1: // to copy it if they are. In fact copying the file will most likely result in
webmaster@1: // a 0 byte file. Which is bad. Real bad.
webmaster@1: if ($source != realpath($dest)) {
webmaster@1: if (!$dest = file_destination($dest, $replace)) {
webmaster@1: drupal_set_message(t('The selected file %file could not be copied, because a file by that name already exists in the destination.', array('%file' => $source)), 'error');
webmaster@1: return FALSE;
webmaster@1: }
webmaster@1:
webmaster@1: if (!@copy($source, $dest)) {
webmaster@1: drupal_set_message(t('The selected file %file could not be copied.', array('%file' => $source)), 'error');
webmaster@1: return 0;
webmaster@1: }
webmaster@1:
webmaster@1: // Give everyone read access so that FTP'd users or
webmaster@1: // non-webserver users can see/read these files,
webmaster@1: // and give group write permissions so group members
webmaster@1: // can alter files uploaded by the webserver.
webmaster@1: @chmod($dest, 0664);
webmaster@1: }
webmaster@1:
webmaster@1: if (isset($file) && is_object($file)) {
webmaster@1: $file->filename = $basename;
webmaster@1: $file->filepath = $dest;
webmaster@1: $source = $file;
webmaster@1: }
webmaster@1: else {
webmaster@1: $source = $dest;
webmaster@1: }
webmaster@1:
webmaster@1: return 1; // Everything went ok.
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Determines the destination path for a file depending on how replacement of
webmaster@1: * existing files should be handled.
webmaster@1: *
webmaster@1: * @param $destination A string specifying the desired path.
webmaster@1: * @param $replace Replace behavior when the destination file already exists.
webmaster@1: * - FILE_EXISTS_REPLACE - Replace the existing file
webmaster@1: * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is
webmaster@1: * unique
webmaster@1: * - FILE_EXISTS_ERROR - Do nothing and return FALSE.
webmaster@1: * @return The destination file path or FALSE if the file already exists and
webmaster@1: * FILE_EXISTS_ERROR was specified.
webmaster@1: */
webmaster@1: function file_destination($destination, $replace) {
webmaster@1: if (file_exists($destination)) {
webmaster@1: switch ($replace) {
webmaster@1: case FILE_EXISTS_RENAME:
webmaster@1: $basename = basename($destination);
webmaster@1: $directory = dirname($destination);
webmaster@1: $destination = file_create_filename($basename, $directory);
webmaster@1: break;
webmaster@1:
webmaster@1: case FILE_EXISTS_ERROR:
webmaster@1: drupal_set_message(t('The selected file %file could not be copied, because a file by that name already exists in the destination.', array('%file' => $destination)), 'error');
webmaster@1: return FALSE;
webmaster@1: }
webmaster@1: }
webmaster@1: return $destination;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Moves a file to a new location.
webmaster@1: * - Checks if $source and $dest are valid and readable/writable.
webmaster@1: * - Performs a file move if $source is not equal to $dest.
webmaster@1: * - If file already exists in $dest either the call will error out, replace the
webmaster@1: * file or rename the file based on the $replace parameter.
webmaster@1: *
webmaster@1: * @param $source A string specifying the file location of the original file.
webmaster@1: * This parameter will contain the resulting destination filename in case of
webmaster@1: * success.
webmaster@1: * @param $dest A string containing the directory $source should be copied to.
webmaster@1: * If this value is omitted, Drupal's 'files' directory will be used.
webmaster@1: * @param $replace Replace behavior when the destination file already exists.
webmaster@1: * - FILE_EXISTS_REPLACE - Replace the existing file
webmaster@1: * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
webmaster@1: * - FILE_EXISTS_ERROR - Do nothing and return FALSE.
webmaster@1: * @return True for success, FALSE for failure.
webmaster@1: */
webmaster@1: function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
webmaster@1: $path_original = is_object($source) ? $source->filepath : $source;
webmaster@1:
webmaster@1: if (file_copy($source, $dest, $replace)) {
webmaster@1: $path_current = is_object($source) ? $source->filepath : $source;
webmaster@1:
webmaster@1: if ($path_original == $path_current || file_delete($path_original)) {
webmaster@1: return 1;
webmaster@1: }
webmaster@1: drupal_set_message(t('The removal of the original file %file has failed.', array('%file' => $path_original)), 'error');
webmaster@1: }
webmaster@1: return 0;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Munge the filename as needed for security purposes. For instance the file
webmaster@1: * name "exploit.php.pps" would become "exploit.php_.pps".
webmaster@1: *
webmaster@1: * @param $filename The name of a file to modify.
webmaster@1: * @param $extensions A space separated list of extensions that should not
webmaster@1: * be altered.
webmaster@1: * @param $alerts Whether alerts (watchdog, drupal_set_message()) should be
webmaster@1: * displayed.
webmaster@1: * @return $filename The potentially modified $filename.
webmaster@1: */
webmaster@1: function file_munge_filename($filename, $extensions, $alerts = TRUE) {
webmaster@1: $original = $filename;
webmaster@1:
webmaster@1: // Allow potentially insecure uploads for very savvy users and admin
webmaster@1: if (!variable_get('allow_insecure_uploads', 0)) {
webmaster@1: $whitelist = array_unique(explode(' ', trim($extensions)));
webmaster@1:
webmaster@1: // Split the filename up by periods. The first part becomes the basename
webmaster@1: // the last part the final extension.
webmaster@1: $filename_parts = explode('.', $filename);
webmaster@1: $new_filename = array_shift($filename_parts); // Remove file basename.
webmaster@1: $final_extension = array_pop($filename_parts); // Remove final extension.
webmaster@1:
webmaster@1: // Loop through the middle parts of the name and add an underscore to the
webmaster@1: // end of each section that could be a file extension but isn't in the list
webmaster@1: // of allowed extensions.
webmaster@1: foreach ($filename_parts as $filename_part) {
webmaster@1: $new_filename .= '.'. $filename_part;
webmaster@1: if (!in_array($filename_part, $whitelist) && preg_match("/^[a-zA-Z]{2,5}\d?$/", $filename_part)) {
webmaster@1: $new_filename .= '_';
webmaster@1: }
webmaster@1: }
webmaster@1: $filename = $new_filename .'.'. $final_extension;
webmaster@1:
webmaster@1: if ($alerts && $original != $filename) {
webmaster@1: drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $filename)));
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: return $filename;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Undo the effect of upload_munge_filename().
webmaster@1: *
webmaster@1: * @param $filename string filename
webmaster@1: * @return string
webmaster@1: */
webmaster@1: function file_unmunge_filename($filename) {
webmaster@1: return str_replace('_.', '.', $filename);
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Create a full file path from a directory and filename. If a file with the
webmaster@1: * specified name already exists, an alternative will be used.
webmaster@1: *
webmaster@1: * @param $basename string filename
webmaster@1: * @param $directory string directory
webmaster@1: * @return
webmaster@1: */
webmaster@1: function file_create_filename($basename, $directory) {
webmaster@1: $dest = $directory .'/'. $basename;
webmaster@1:
webmaster@1: if (file_exists($dest)) {
webmaster@1: // Destination file already exists, generate an alternative.
webmaster@1: if ($pos = strrpos($basename, '.')) {
webmaster@1: $name = substr($basename, 0, $pos);
webmaster@1: $ext = substr($basename, $pos);
webmaster@1: }
webmaster@1: else {
webmaster@1: $name = $basename;
webmaster@1: }
webmaster@1:
webmaster@1: $counter = 0;
webmaster@1: do {
webmaster@1: $dest = $directory .'/'. $name .'_'. $counter++ . $ext;
webmaster@1: } while (file_exists($dest));
webmaster@1: }
webmaster@1:
webmaster@1: return $dest;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Delete a file.
webmaster@1: *
webmaster@1: * @param $path A string containing a file path.
webmaster@1: * @return TRUE for success, FALSE for failure.
webmaster@1: */
webmaster@1: function file_delete($path) {
webmaster@1: if (is_file($path)) {
webmaster@1: return unlink($path);
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Determine total disk space used by a single user or the whole filesystem.
webmaster@1: *
webmaster@1: * @param $uid
webmaster@1: * An optional user id. A NULL value returns the total space used
webmaster@1: * by all files.
webmaster@1: */
webmaster@1: function file_space_used($uid = NULL) {
webmaster@1: if (isset($uid)) {
webmaster@1: return (int) db_result(db_query('SELECT SUM(filesize) FROM {files} WHERE uid = %d', $uid));
webmaster@1: }
webmaster@1: return (int) db_result(db_query('SELECT SUM(filesize) FROM {files}'));
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Saves a file upload to a new location. The source file is validated as a
webmaster@1: * proper upload and handled as such.
webmaster@1: *
webmaster@1: * The file will be added to the files table as a temporary file. Temporary files
webmaster@1: * are periodically cleaned. To make the file permanent file call
webmaster@1: * file_set_status() to change its status.
webmaster@1: *
webmaster@1: * @param $source
webmaster@1: * A string specifying the name of the upload field to save.
webmaster@1: * @param $validators
webmaster@1: * An optional, associative array of callback functions used to validate the
webmaster@1: * file. The keys are function names and the values arrays of callback
webmaster@1: * parameters which will be passed in after the user and file objects. The
webmaster@1: * functions should return an array of error messages, an empty array
webmaster@1: * indicates that the file passed validation. The functions will be called in
webmaster@1: * the order specified.
webmaster@1: * @param $dest
webmaster@1: * A string containing the directory $source should be copied to. If this is
webmaster@1: * not provided or is not writable, the temporary directory will be used.
webmaster@1: * @param $replace
webmaster@1: * A boolean indicating whether an existing file of the same name in the
webmaster@1: * destination directory should overwritten. A false value will generate a
webmaster@1: * new, unique filename in the destination directory.
webmaster@1: * @return
webmaster@1: * An object containing the file information, or 0 in the event of an error.
webmaster@1: */
webmaster@1: function file_save_upload($source, $validators = array(), $dest = FALSE, $replace = FILE_EXISTS_RENAME) {
webmaster@1: global $user;
webmaster@1: static $upload_cache;
webmaster@1:
webmaster@1: // Add in our check of the the file name length.
webmaster@1: $validators['file_validate_name_length'] = array();
webmaster@1:
webmaster@1: // Return cached objects without processing since the file will have
webmaster@1: // already been processed and the paths in _FILES will be invalid.
webmaster@1: if (isset($upload_cache[$source])) {
webmaster@1: return $upload_cache[$source];
webmaster@1: }
webmaster@1:
webmaster@1: // If a file was uploaded, process it.
webmaster@1: if (isset($_FILES['files']) && $_FILES['files']['name'][$source] && is_uploaded_file($_FILES['files']['tmp_name'][$source])) {
webmaster@1: // Check for file upload errors and return FALSE if a
webmaster@1: // lower level system error occurred.
webmaster@1: switch ($_FILES['files']['error'][$source]) {
webmaster@1: // @see http://php.net/manual/en/features.file-upload.errors.php
webmaster@1: case UPLOAD_ERR_OK:
webmaster@1: break;
webmaster@1:
webmaster@1: case UPLOAD_ERR_INI_SIZE:
webmaster@1: case UPLOAD_ERR_FORM_SIZE:
webmaster@1: drupal_set_message(t('The file %file could not be saved, because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $source, '%maxsize' => format_size(file_upload_max_size()))), 'error');
webmaster@1: return 0;
webmaster@1:
webmaster@1: case UPLOAD_ERR_PARTIAL:
webmaster@1: case UPLOAD_ERR_NO_FILE:
webmaster@1: drupal_set_message(t('The file %file could not be saved, because the upload did not complete.', array('%file' => $source)), 'error');
webmaster@1: return 0;
webmaster@1:
webmaster@1: // Unknown error
webmaster@1: default:
webmaster@1: drupal_set_message(t('The file %file could not be saved. An unknown error has occurred.', array('%file' => $source)), 'error');
webmaster@1: return 0;
webmaster@1: }
webmaster@1:
webmaster@1: // Build the list of non-munged extensions.
webmaster@1: // @todo: this should not be here. we need to figure out the right place.
webmaster@1: $extensions = '';
webmaster@1: foreach ($user->roles as $rid => $name) {
webmaster@1: $extensions .= ' '. variable_get("upload_extensions_$rid",
webmaster@1: variable_get('upload_extensions_default', 'jpg jpeg gif png txt html doc xls pdf ppt pps odt ods odp'));
webmaster@1: }
webmaster@1:
webmaster@1: // Begin building file object.
webmaster@1: $file = new stdClass();
webmaster@1: $file->filename = file_munge_filename(trim(basename($_FILES['files']['name'][$source]), '.'), $extensions);
webmaster@1: $file->filepath = $_FILES['files']['tmp_name'][$source];
webmaster@1: $file->filemime = $_FILES['files']['type'][$source];
webmaster@1:
webmaster@1: // Rename potentially executable files, to help prevent exploits.
webmaster@1: if (preg_match('/\.(php|pl|py|cgi|asp|js)$/i', $file->filename) && (substr($file->filename, -4) != '.txt')) {
webmaster@1: $file->filemime = 'text/plain';
webmaster@1: $file->filepath .= '.txt';
webmaster@1: $file->filename .= '.txt';
webmaster@1: }
webmaster@1:
webmaster@1: // If the destination is not provided, or is not writable, then use the
webmaster@1: // temporary directory.
webmaster@1: if (empty($dest) || file_check_path($dest) === FALSE) {
webmaster@1: $dest = file_directory_temp();
webmaster@1: }
webmaster@1:
webmaster@1: $file->source = $source;
webmaster@1: $file->destination = file_destination(file_create_path($dest .'/'. $file->filename), $replace);
webmaster@1: $file->filesize = $_FILES['files']['size'][$source];
webmaster@1:
webmaster@1: // Call the validation functions.
webmaster@1: $errors = array();
webmaster@1: foreach ($validators as $function => $args) {
webmaster@1: array_unshift($args, $file);
webmaster@1: $errors = array_merge($errors, call_user_func_array($function, $args));
webmaster@1: }
webmaster@1:
webmaster@1: // Check for validation errors.
webmaster@1: if (!empty($errors)) {
webmaster@1: $message = t('The selected file %name could not be uploaded.', array('%name' => $file->filename));
webmaster@1: if (count($errors) > 1) {
webmaster@1: $message .= '