/** * Upload File */ protected function _do_upload_in_folder($folder_data, $temp_file_path, $original_name) { $filedir = $this->get_filedir($folder_data->filedir_id); // make sure the file is under the Max File Size limit, if set if ($filedir->max_size && filesize($temp_file_path) > $filedir->max_size) { $error = $this->EE->functions->var_swap(lang('file_too_large'), array('max_size' => Assets_helper::format_filesize($filedir->max_size))); return array('error' => $error); } $server_path = $this->get_folder_server_path($folder_data->full_path, $folder_data); // make sure this is a valid upload directory path if (!$server_path) { return array('error' => lang('invalid_filedir_path')); } // make sure the folder is writable if (!is_writable($server_path)) { return array('error' => lang('filedir_not_writable')); } $original_name = $this->EE->assets_lib->clean_filename($original_name); $file_path = $server_path . $original_name; $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION)); $file_kinds = Assets_helper::get_file_kinds(); $is_image = in_array($ext, $file_kinds['image']); // make sure the file is an image, if Allowed Types is set to Images Only if ($filedir->allowed_types == 'img' && !$is_image) { return array('error' => lang('images_only_allowed')); } if (!$this->_is_extension_allowed($ext)) { return array('error' => lang('filetype_not_allowed')); } if (file_exists($file_path) or empty($this->cache['merge_in_progress']) && $this->EE->assets_lib->get_file_id_by_folder_id_and_name($folder_data->folder_id, $original_name)) { return $this->_prompt_result_array($original_name); } // make sure the filename is clean and unique $this->_prep_filename($file_path); // copy here, since it will be unlinked later on if (!copy($temp_file_path, $file_path)) { return array('error' => lang('couldnt_save')); } @chmod($file_path, FILE_WRITE_MODE); $source_server_path = $this->get_filedir($folder_data->filedir_id)->server_path; // for top level folders, add it to the exp_files table. if (empty($folder_data->parent_id) && substr($source_server_path, 0, 3) != '../' && strpos($source_server_path, SYSDIR) === FALSE) { $this->_store_file_data($file_path, $filedir->id); } else { if ($is_image) { $this->EE->assets_lib->call_extension('assets_ee_subfolder_upload', array($file_path)); $this->_create_thumbnails($file_path, $filedir->id); } } return array('success' => TRUE, 'path' => $file_path); }