Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
Prev Previous Post   Next Post Next
  #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
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:50 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03422 seconds
  • Memory Usage 2,285KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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_threadedmode.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete