Back to Programming Articles

Upload images using the datamanager.
by waza 03 Mar 2006

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

vblts.ru supports vBulletin®, 2022-2024