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
  #2  
Old 03-03-2006, 06:47 PM
DrewM DrewM is offline
 
Join Date: Oct 2005
Posts: 564
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Asome thanks
Reply With Quote
  #3  
Old 04-22-2006, 09:32 PM
Impreza04 Impreza04 is offline
 
Join Date: Jul 2005
Location: UK
Posts: 99
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the tutorial, problem is that it doesn't check for files with the same name and just overwrites them.

Anyone know a way around this
Reply With Quote
  #4  
Old 05-01-2006, 06:05 AM
SiMateoAko SiMateoAko is offline
 
Join Date: Apr 2006
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Impreza04
Thanks for the tutorial, problem is that it doesn't check for files with the same name and just overwrites them.

Anyone know a way around this
Not sure of the exact code, but how about uploading it to a temp directory, giving it a new filename and then moving it to the proper directory?
Reply With Quote
  #5  
Old 11-04-2006, 06:37 PM
johnstires johnstires is offline
 
Join Date: Mar 2006
Posts: 195
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'd like to create something like this, but the problem I'm having with the directions is where does everything go? Where do I place the html and php code?
Reply With Quote
  #6  
Old 01-29-2007, 02:31 PM
timedgar timedgar is offline
 
Join Date: Jan 2007
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm wondering if the class has features to put the image right into the DB. I know there is debate about doing that, but I like it for small things like product images, etc.

Also, are functions included for displaying the image, either out of the DB or from disk? 'twould be nice.

Thanks,

Tim
Reply With Quote
  #7  
Old 06-28-2008, 01:43 PM
aussiev8 aussiev8 is offline
 
Join Date: Aug 2004
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I know this is really old.. but to change the filename you can simply
$vbulletin->GPC['upload']['name'] = "blah";
This could cause unexpected bugs..
best thing to do is attempt to separate the files into directories.. maybe by user/thread/etc. etc.
Reply With Quote
  #8  
Old 09-21-2008, 07:17 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by aussiev8 View Post
I know this is really old.. but to change the filename you can simply
$vbulletin->GPC['upload']['name'] = "blah";
This could cause unexpected bugs..
best thing to do is attempt to separate the files into directories.. maybe by user/thread/etc. etc.
With this I couldnt rename that file I just uploaded.
Can someone help me with renaming the file?
thank you so much
Reply With Quote
  #9  
Old 02-15-2009, 12:57 AM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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...
Reply With Quote
  #10  
Old 02-21-2009, 06:03 AM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

shouldn't this thread also be in the vb area and not programming?
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 05:52 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.04406 seconds
  • Memory Usage 2,300KB
  • Queries Executed 23 (?)
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
  • (3)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (2)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
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)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