vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Programming Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=188)
-   -   Upload images using the datamanager. (https://vborg.vbsupport.ru/showthread.php?t=109376)

waza 03-02-2006 10:00 PM

Upload images using the datamanager.
 
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

DrewM 03-03-2006 06:47 PM

Asome thanks

Impreza04 04-22-2006 09:32 PM

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

SiMateoAko 05-01-2006 06:05 AM

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?

johnstires 11-04-2006 06:37 PM

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?

timedgar 01-29-2007 02:31 PM

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

aussiev8 06-28-2008 01:43 PM

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.

mokujin 09-21-2008 07:17 PM

Quote:

Originally Posted by aussiev8 (Post 1561238)
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

Jaxel 02-15-2009 12:57 AM

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...

ragtek 02-21-2009 06:03 AM

shouldn't this thread also be in the vb area and not programming?


All times are GMT. The time now is 10:38 AM.

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.02532 seconds
  • Memory Usage 1,746KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_html_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete