Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Upload images using the datamanager.
waza
Join Date: Apr 2005
Posts: 341

Made in belgium

Belgium
Show Printable Version Email this Page Subscription
waza waza is offline 03-02-2006, 10:00 PM

Hey,
In this tutorial I'll try to show you how you can upload images using the vb datamanaging class.

First of all you have to make a special form to upload images.
Like this:
HTML Code:
<form method="post" enctype="multipart/form-data" action="portfolio.php">
<input type="hidden" name="do" value="doupload" /><b>Upload new image:</b><br />
<input type="file" name="upload" />
<br />
<input type="submit" value="add" />
</form>
So make sure you have this:
<form method="post" enctype="multipart/form-data">
and <input type="file" name="upload">

then you can create a php file to process the upload.
like this:

PHP Code:
if($_POST['do']=="doupload"){
$vbulletin->input->clean_gpc("f","upload",TYPE_FILE);
require_once(
'./includes/class_upload.php');
require_once(
'./includes/class_image.php');
$upload = new vB_Upload_Image($vbulletin);
$upload->image =& vB_Image::fetch_library($vbulletin);
$upload->path "./image/misc/";
if (!(
$upload->process_upload($vbulletin->GPC['upload']))){
        eval(
standard_error(fetch_error('there_were_errors_encountered_with_your_upload_x'$upload->fetch_error())));
    }

So this:
$vbulletin->input->clean_gpc("f","upload",TYPE_FILE); cleans the file
$upload->path is the path to where the image has to be uploaded
$vbulletin->GPC['upload'] is the file containing ($vbulletin->GPC['upload'][x]):
-name: The name of the image
-type: the mime type of the image, like: image/gif
-tmp_name: the temporary name when the image is uploading
-size: the filesize in bytes

I hope this can help you
regards,
seba
Reply With Quote
  #12  
Old 02-22-2009, 12:01 PM
bananalive bananalive is offline
 
Join Date: Oct 2007
Location: UK
Posts: 2,802
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jaxel View Post
I'm having problems using this... this is my code...

Code:
$file = $vbulletin->input->clean_gpc("f","upload",TYPE_FILE);
if ($file)
{
	upload_game($game);
}
Code:
function upload_game($game)
{
	global $vbulletin, $filename, $thumbdir;

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

	$upload = new vB_Upload_Image($vbulletin); 
	$upload->image =& vB_Image::fetch_library($vbulletin); 
	$upload->path = "./".$thumbdir."/games";

	$vbulletin->GPC['upload']['name'] = $game['gameID'].".jpg";

	if (!($upload->process_upload($vbulletin->GPC['upload'])))
	{ 
   		eval(standard_error(fetch_error('there_were_errors_encountered_with_your_upload_x', $upload->fetch_error()))); 
	}
 
	$vbulletin->url = $filename.'?do=games';
	eval(print_standard_redirect('redirect_rankgame_edited'));
}
This should work... but I'm getting the following error...
Code:
There was an error encountered with your upload:

This JPEG image has the incorrect file extension.
Any ideas? I am uploading a file called sc4.jpg...
Code:
$file = $vbulletin->input->clean_gpc("f","upload",TYPE_FILE);
if ($file)
{
	upload_game($file);
}
Reply With Quote
  #13  
Old 03-08-2009, 03:46 AM
rob01 rob01 is offline
 
Join Date: Sep 2008
Location: Mexico
Posts: 410
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

is it possible to show the images uploaded inside the page?
Reply With Quote
Reply


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 06:26 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03650 seconds
  • Memory Usage 2,225KB
  • Queries Executed 17 (?)
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
  • (4)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (2)postbit
  • (3)postbit_onlinestatus
  • (3)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_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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete