⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfiles.php

📁 一款文件上传程序
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
define ( 'MYFILES_PHP', 1 );
require_once 'includes/commons.inc.php';
require_once 'includes/message_myfiles.inc.php';
$tpl_myfiles = new Template ( TPL_DIR .  '/tpl_myfiles.php' );
$tpl_error = new Template ( TPL_DIR .  '/tpl_error.php' );

// User directory and URL
$userid = $UPL['USER']['userid'];
$userfiles_url = $UPL['SETTINGS']['userfiles_url'];

$uploader_view = $UPL['SETTINGS']['uploader_view'];

// Check user's folder
if ( !is_dir ( USERFILES_ROOT ) )
{
	$tpl_message->set ( 'message', parse ( $lang_myfiles['folder_no_exists'], '{username}', $UPL['USER']['username'] ) );
	$tpl_uploader->setr ( 'content', $tpl_message, 1 );
	exit;
}

// wut doing?
switch ( $action )
{
	case 'refresh':
	{
		clear_contents_cache ( USERFILES_ROOT );
		go_to(MOD_REWRITE?'myfiles/':'myfiles.php');
	}
	break;

	case 'move':
	{
		// for image resize
		require_once 'includes/functions_img.inc.php';
		$files  = gpc ( 'files', 'P', array ( ) );
		$folder = path_decode ( gpc ( 'folder', 'P' ) ); 		// current folder
		$dest   = path_decode ( gpc ( 'move_to', 'P', '' ) ); 	// move to this folder

		if ( $folder != $dest && is_array ( $files ) && count ( $files ) && is_dir ( USERFILES_ROOT . $folder )  && check_path ( USERFILES_ROOT, USERFILES_ROOT . $dest ) && is_dir ( USERFILES_ROOT . $dest ) )
		{
			$fc = count ( $files );
			$src = USERFILES_ROOT . $folder . '/';
			$dst = USERFILES_ROOT . $dest . '/';
			$dst_info = get_folder_info ( $dst );
			$errors = array();

			for ( $i = 0; $i < $fc; ++$i )
			{
				$file = rawurldecode ( $files[$i] );

				if ( $file == '' || !is_file ( $src . $file ) || !check_path ( USERFILES_ROOT, $src . $file ) ) continue;
				if ( file_exists ( $dst . $file ) )
				{
					$errors[] = parse ( $lang_myfiles['move_exists'], '{filename}', $file );
					continue;
				}
				$src_path = $src . $file;
				$dst_path = $dst . $file;
				$src_thumb_path = $src . 'thumbs/' . $file;
				$dst_thumb_path = $dst . 'thumbs/' . $file;

				if ( $dst_info['is_gallery'] )
				{
					if ( !is_image ( $src_path ) )
					{
						$errors[] = parse ( $lang_myfiles['move_non_image'], '{filename}', $file );
						continue;
					}
					else
					{
						// move the image
						@rename ( $src_path, $dst_path );
						// if there is a thumbnail for this image, move it too
						if ( is_file ( $src_thumb_path ) )
						{
							@rename ( $src_thumb_path, $dst_thumb_path );
						}
						else
						{
							// no thumbnail for this image, which means a thumbnail has to be created
							list ( $new_width, $new_height ) = explode ( 'x', $UPL['CONFIGS']['THUMBNAIL_GALLERY'] );
							if ( !img_resize ( $dst_path, $dst_thumb_path, $new_width, $new_height, $UPL['CONFIGS']['THUMBNAIL_BORDER'] ) )
							{
								exit ( 'Internal error: img_resize failed to create thumbnails in myfiles.php on line ' . __LINE__ );
							}
						}
					}
				}
				else
				{
					// copy the file
					@rename ( $src_path, $dst_path );
					// if there is a thumbnail for this image, remove it
					@unlink ( $src_thumb_path );
				}
			}
			clear_contents_cache ( USERFILES_ROOT );
		}
		$back_url = isset ( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'myfiles.php';

		if ( count ( $errors ) )
		{
			$tpl_message->set ( 'message_title', $lang_myfiles['files_not_moved'] );
			$tpl_message->set ( 'message', $errors );
			$tpl_message->set ( 'back_url', $back_url );
			$tpl_uploader->setr ( 'content', $tpl_message, 1 );
		}
		else
		{
			go_to ( $back_url );
		}
	}
	break;

	case 'img_tags':
	{
		$tpl_img = new Template ( TPL_DIR . 'tpl_img.php' );
		$files   = gpc ( 'files', 'P', array ( ) );
		$folder  = path_decode ( gpc ( 'folder', 'P' ) );
		$fc 	 = count ( $files );
		if ( is_array ( $files ) && $fc )
		{
			$list = array ( );
			for ( $i = 0; $i < $fc; ++$i )
			{
				$file = path_decode ( $files[$i] );
				$file_path = USERFILES_ROOT . $folder . '/' . $file;

				$has_thumb = is_file ( USERFILES_ROOT . $folder . '/thumbs/' . $file );

				$f = array
				(
					'name' 		=> $file,
					'link' 		=> USERFILES_URL . clean_url ( ( $folder == '' ? '' : $folder . '/' ) . rawurlencode ( $file ) ),
					'url' 		=> USERFILES_URL . clean_url ( ( $folder == '' ? '' : $folder . '/' ) . rawurlencode ( $file ) ),
					'has_thumb' => $has_thumb,
					'thumb_url' => $has_thumb ? ( USERFILES_URL . clean_url ( $folder == '' ? '' : $folder . '/' ) . 'thumbs/' . rawurlencode ( $file ) ) : ''
				);

				if ( is_image ( $file_path ) )
				{
					if ( MOD_REWRITE )
					{
						$f['link'] = $userfiles_url . ( $uploader_view ? 'view/' : '' ) . $userid . '/' . trim ( clean_url ( $folder . '/' . rawurlencode ( $f['name'] ) ), '/' );
					}
					elseif ( $uploader_view ) $f['link'] = $UPL['SETTINGS']['uploader_url'] . 'view.php?userid=' . $userid . '&file=' . trim ( clean_url ( $folder . '/' . rawurlencode ( $f['name'] ) ), '/' );
				}
				$list[] = $f;
			}
			$tpl_img->setr ( 'images', $list );
			$tpl_img->set ( 'back_url', 'myfiles.php' . ( $folder != '' ? '?folder=' . path_encode ( $folder ) : '' ) );
			$tpl_uploader->set ( array ( 'page_title' => $lang_titles['mf_img_title1'], 'content' => &$tpl_img ), '', 1 );
			return;
		}
		go_to ( ( isset ( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'myfiles.php' ) );
	}
	break;



	case 'delete':
	{
		if ( $demo ) exit ( "Demo mode, deleting files not allowed" );

		$files  = gpc('files','P',array());
		$folder = path_decode(gpc('folder','P'));

		if ( !check_path ( USERFILES_ROOT, USERFILES_ROOT . $folder ) ) exit(SECURITY_ERROR);

		// delete them
		$deleted = array ();
		if ( is_array ( $files ) && is_dir ( USERFILES_ROOT . $folder ) )
		{
			$fc = count ( $files );
			$path = USERFILES_ROOT . $folder . '/';

			for ( $i = 0; $i < $fc; ++$i )
			{
				$file = rawurldecode ( $files[$i] );
				if ( $file != '' && is_file ( $path . $file ) && check_path ( USERFILES_ROOT, $path. $file ) )
				{
					@unlink ( $path . $file );
					// delete thumbnail too
					@unlink ( $path . 'thumbs/' . $file );
					// record
					$deleted [] = $file;
				}
			}
			// update cache
			if ( count ( $deleted ) )
			{
				clear_contents_cache ( USERFILES_ROOT );
			}
			//log deletion?
			if ( $UPL['SETTINGS']['log'] >= 2 )
			{
				$log_file = LOGS_DIR . date ( 'M_d_Y' ) . '.log';
				$fp = fopen ( $log_file, 'a+' );
				if ( $fp && flock ( $fp, LOCK_EX ) )
				{
					$dc = count ( $deleted );
					for ( $i = 0; $i < $dc; ++$i )
					{
						fwrite ( $fp, sprintf ( "%s(%s) deleted %s at %s\r\n", $UPL['USER']['username'], $_SERVER['REMOTE_ADDR'], $deleted[$i], date ( 'h:mA' ) ) );
					}
					fclose ( $fp );
				}
			}
		}
		go_to ( ( isset ( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'myfiles.php' ) );
	}
	break;


	case 'resize':
	{
		require_once 'includes/functions_img.inc.php';
		$tpl_resize = new Template ( TPL_DIR . 'tpl_resize.php' );

		// is GD enabled?
		if ( !function_exists ( 'imagecreatetruecolor' ) )
		{
			$tpl_message->set ( 'message', $lang_myfiles['no_gd'] );
			$tpl_message->set ( 'back_url', 'myfiles.php' );
			$tpl_uploader->set ( 'content', $tpl_message, 1 );
			exit;
		}

		if ( $task == 'resize' )
		{
			$file_path = path_decode ( gpc ( 'file_path', 'P', '' ) );
			$file_name = trim ( gpc ( 'file_name', 'P', '' ) );
			$file_width = abs ( intval ( gpc ( 'file_width', 'P', 0 ) ) );
			$file_height = abs ( intval ( gpc ( 'file_height', 'P', 0 ) ) );

			$new_file_path = dir_name ( $file_path ) . '/' . $file_name;


			if ( $file_path == '' || strstr ( $file_path, '../' ) || !is_file ( USERFILES_ROOT . $file_path )  ) $error = $lang_myfiles['file_not_supported'];
			elseif ( !is_image ( USERFILES_ROOT . $file_path, true ) ) $error = $lang_myfiles['type_not_supported'];
			else $error = 'none';

			if ( $error == 'none' )
			{
				// no error so far, try to resize
				$file_info = @getimagesize ( USERFILES_ROOT . $file_path );
				if ( !is_array ( $file_info ) ) $error = $lang_myfiles['type_not_supported'];
				elseif ( $file_width == 0 || $file_height == 0 ) $error = $lang_myfiles['zero_dimension'];
				elseif ( $file_width >= $file_info[0] || $file_height >= $file_info[1] ) $error = $lang_myfiles['smaller_only'];
				elseif ( preg_match ( $UPL['CONFIGS']['REGEX_INVALID_CHARS'], $file_name ) ) $error = $lang_myfiles['invalid_char_filename'];
				elseif ( !preg_match ( '#[a-z0-9]#i', $file_name[0] ) ) $error = $lang_myfiles['alpha_prefix'];
				elseif ( is_dir ( USERFILES_ROOT . $new_file_path ) ) $error = $lang_myfiles['new_name_conflict'];
				elseif ( !img_resize ( USERFILES_ROOT . $file_path, USERFILES_ROOT . $new_file_path, $file_width, $file_height, $UPL['CONFIGS']['THUMBNAIL_BORDER'] ) ) $error = 'Internal error, image_resize() failed.';
				else $error = 'none';

				if ( $error == 'none' )
				{
					// clear cache
					clear_contents_cache ( USERFILES_ROOT );

					// success
					$tpl_message->set ( 'back_url', 'myfiles.php?folder=' . path_encode ( dir_name ( $file_path ) ) );
					$tpl_message->set ( 'message', $lang_myfiles['resize_success'] );
					$tpl_uploader->set ( 'content', $tpl_message, 1 );
					exit;
				}
				else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -