芝麻web文件管理V1.00
编辑当前文件:/home/r5772835/public_html/dina.ycreate.jp/wp-content/plugins/snow-monkey-forms/App/Model/File.php
file = $file; } /** * Return $_FILE error. * * @return false|int */ public function get_error() { return isset( $this->file['error'] ) && is_int( $this->file['error'] ) ? $this->file['error'] : false; } /** * Return $_FILE name. * * @return false|string */ public function get_filename() { return isset( $this->file['name'] ) ? $this->_sanitized_file_name( $this->file['name'] ) : false; } /** * Return $_FILE tmp_name. * * @return false|string */ public function get_tmp_name() { return isset( $this->file['tmp_name'] ) ? $this->file['tmp_name'] : false; } /** * Moves an uploaded file to a new location. * * @param array $destination The destination of the moved file. * @return boolean */ protected function _move_to( $destination ) { $tmp_name = $this->get_tmp_name(); return false === $tmp_name ? false : move_uploaded_file( $tmp_name, $destination ); } /** * Return sanitized file name. * * @param string $filename The file name. * @return false|string */ protected function _sanitized_file_name( $filename ) { if ( false === $filename ) { return false; } return sanitize_file_name( basename( $filename ) ); } /** * Save the file. * * @param string $filename Posted file name. * @return string * @throws \RuntimeException When the file upload fails. */ public function save( $filename ) { $filename = $this->_sanitized_file_name( $filename ); $error = $this->get_error(); if ( false === $error || false === $filename ) { throw new \RuntimeException( '[Snow Monkey Forms] An error occurred during file upload.' ); } if ( UPLOAD_ERR_OK !== $error && UPLOAD_ERR_NO_FILE !== $error ) { if ( UPLOAD_ERR_INI_SIZE === $error || UPLOAD_ERR_FORM_SIZE === $error ) { throw new \RuntimeException( '[Snow Monkey Forms] File size of the uploaded file is too large.' ); } throw new \RuntimeException( '[Snow Monkey Forms] An error occurred during file upload.' ); } $save_dir = Directory::get(); if ( ! $save_dir ) { throw new \RuntimeException( '[Snow Monkey Forms] Creation of a temporary directory for file upload failed.' ); } $new_save_dir = ''; $unique_dir = ''; do { $rand_max = mt_getrandmax(); $rand = zeroise( mt_rand( 0, $rand_max ), strlen( $rand_max ) ); $uniqid = md5( uniqid( $rand, true ) ) . $rand; $unique_dir = ! $unique_dir ? $uniqid : path_join( $unique_dir, $uniqid ); $new_save_dir = path_join( $save_dir, $unique_dir ); if ( ! file_exists( $new_save_dir ) ) { break; } } while ( 0 ); if ( ! wp_mkdir_p( $new_save_dir ) ) { throw new \RuntimeException( '[Snow Monkey Forms] Creation of a temporary directory for file upload failed.' ); } $new_filepath = path_join( $new_save_dir, $filename ); if ( ! $this->_move_to( $new_filepath ) ) { throw new \RuntimeException( '[Snow Monkey Forms] There was an error saving the uploaded file.' ); } return path_join( $unique_dir, $filename ); } }