View Single Post
  #1  
Old 03-20-2015, 11:58 AM
Preech Preech is offline
 
Join Date: Aug 2002
Location: Fort Campbell
Posts: 325
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Upload Image from Admincp

Okay, so I have been upgrading this mod https://vborg.vbsupport.ru/showthrea...hlight=vbmusic for awhile now. I was complete but not happy with it. There was some things I wanted to change.

To add a album from the admincp I didn't want just a html link to add to the database. I wanted to give the admin the option to upload a image where it save's the file to the server and inserts the link into the database. I can get the path to show up in the database, but the file doesn't show up in the correct folder. This is my code for creating a album. Please any assistance would be greatly appreciated.

Code:
$tables = array('music_album' => 'Music Album Image');
$itempath = $vbulletin->GPC['table'] . 'path';
		//########### ADD & EDIT ALLBUM #############\\
		
		// ###################### Start Do Upload #######################
if ($_POST['do'] == 'doupload')
{
	$vbulletin->input->clean_array_gpc('f', array(
		'upload'  => TYPE_FILE,
	));

	$vbulletin->input->clean_array_gpc('p', array(
		
		'names' 	=> TYPE_STR,
	    'artistid' => TYPE_UINT,
	    'info'	=> TYPE_STR,
	    'image'     => TYPE_STR,
	    'catid' => TYPE_UINT,
		'length' => TYPE_UINT,
	    'year' => TYPE_UINT,
	    'total_songs' => TYPE_UINT
	));
	
	$vbulletin->input->clean_array_gpc('r', array(
		'id' 	=> TYPE_INT,
		'artistid' => TYPE_UINT
	));


	if (empty($vbulletin->GPC['names']) OR empty($vbulletin->GPC['image']))
	{
		print_stop_message('please_complete_required_fields');
	}
	//if (file_exists('./' . $vbulletin->GPC['image'] . '/' . $vbulletin->GPC['upload']['name']))
	//{
	//	print_stop_message('file_x_already_exists', htmlspecialchars_uni($vbulletin->GPC['upload']['name']));
	//}

	require_once(DIR . '/includes/class_upload.php');
	require_once(DIR . '/includes/class_image.php');

	
	$upload = new vB_Upload_Image($vbulletin);
	$upload->image =& vB_Image::fetch_library($vbulletin);
$upload->path = $vbulletin->GPC['image'];
		$names = $vbulletin->GPC['names'];
	$artistid = $vbulletin->GPC['artistid'];
	$info  = $vbulletin->GPC['info'];
$image = $vbulletin->GPC['image'];
	
	$catid = $vbulletin->GPC['catid'];
	$length = $vbulletin->GPC['length'];
	$year = $vbulletin->GPC['year'];


	//if (!($imagepath = $upload->process_upload($vbulletin->GPC['upload'])))
//	{
	//	print_stop_message('there_were_errors_encountered_with_your_upload_x', $upload->fetch_error());
	//}

	define('IMAGE_UPLOADED', true);
	$_POST['do'] = 'insert';
}
		// ###################### Start Upload #######################
if ($_REQUEST['do'] == 'upload')
{
	print_form_header('vbmusic', 'doupload');
	print_table_header('Add Album');
	print_upload_row($vbphrase['filename'], 'upload');
	print_input_row('Album Title', names, '');
	print_select_row('Artist', 'artistid',fetch_artist_array($artsid));
	print_textarea_row('Album Info', 'info', '');
	print_select_row('Album Genre', 'catid',fetch_category_array($catid));
	print_input_row('Length', 'length', '');
	print_input_row('Year', 'year', '');
	print_input_row('Total Songs', 'total_songs', '');
	print_input_row($vbphrase["{$itemtype}_file_path_dfn"], 'image', 'vbmusic/photos/', 'upload');
	//print_input_row('Album Image Path',image, $vbulletin->options['vbmusic_image_path'],'image' );
	print_submit_row($vbphrase['upload']);
}

// ###################### Start Insert #######################
if ($_POST['do'] == 'insert')
{
	$vbulletin->input->clean_array_gpc('p', array(
	'imagespath' => TYPE_STR,
	'names' 	=> TYPE_STR,
	    'artistid' => TYPE_UINT,
	    'info'	=> TYPE_STR,
	    'image'     => TYPE_STR,
	    'catid' => TYPE_UINT,
		'length' => TYPE_UINT,
	    'year' => TYPE_UINT,
	    'total_songs' => TYPE_UINT
	));

	//if (!$vbulletin->GPC['image'] OR (!$vbulletin->GPC['names'])
	//{
	//	print_stop_message('please_complete_required_fields');
	//}

	//if ($vbulletin->GPC['table'] == 'smilie' AND $db->query_first("SELECT smilieid FROM " . TABLE_PREFIX . $vbulletin->GPC['table'] . " WHERE BINARY smilietext = '" . $db->escape_string($vbulletin->GPC['smilietext']) . "'"))
	//{
		if (IMAGE_UPLOADED AND file_exists($imagepath))
		{ // if the image is being uploaded zap it
			unlink($imagepath);
		}
		// this smilie already exists
		//print_stop_message('smilie_replace_text_x_exists', $vbulletin->GPC['smilietext']);
	//}

	if (IMAGE_UPLOADED !== true)
	{
		// we are adding a single item via the form, use user input for path
		$imagepath =& $vbulletin->GPC['imagespath'];
	}

	/*insert query*/
	$db->query_write("
		INSERT INTO " . TABLE_PREFIX . "music_album
		(`name`, `artistid`, `info`, `image`, `catid`,`length`,`year`,`total_songs`)VALUES('" . addslashes($names) . "', '$artistid', '" . addslashes($info) . "', '" . addslashes($image) . "', '$catid','" . addslashes($length) . "','" . addslashes($year) . "','" . addslashes($total_songs) . "')");

	//build_image_cache($vbulletin->GPC['table']);
	//build_image_permissions($vbulletin->GPC['table']);

	//if ($itemtype == 'avatar')
	//{
	//	print_stop_message('need_to_rebuild_avatars');
	//}
	//else
	//{
		exec_header_redirect("vbmusic.php?do=updatealbum");
	exit;
	}
//}
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01274 seconds
  • Memory Usage 1,800KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete