Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #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
  #2  
Old 03-21-2015, 01:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'll confess that I haven't studied the code you posted to understand why it isn't working. I spent years working as a software developer and writing object oriented code, but now I don't have the patience to figure out all the class stuff. I guess I'm more of a hacker when it comes to vbulletin. So anyway, I can't tell you why what you are doing doesn't work, but I could suggest that you try something simpler like google for php sample code to handle uploaded files, or maybe look at admincp/diagnostics.php where do='doupload'. You probably just need to get the name of the temp path to the uploaded file and it's intended name, then rename/move it to the directory you want. Since this is only for admins, it saves you worrying too much about permissions, file types and sizes, etc (well, assuming you trust your admins).
Reply With Quote
Reply

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 02:17 PM.


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.04088 seconds
  • Memory Usage 2,186KB
  • Queries Executed 13 (?)
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)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (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)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_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
  • 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