vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Error with image file upload (https://vborg.vbsupport.ru/showthread.php?t=168612)

Mythotical 01-24-2008 04:06 AM

Error with image file upload
 
I have added the file image upload code while I wait on a response regarding file image upload to database.

Anyway, here is the code I'm using thus far:
PHP Code:

if($_REQUEST['do'] == 'saved')
    {    
    
$upload = new vB_Upload_Image($vbulletin);
    
$upload->image =& vB_Image::fetch_library($vbulletin);
    
$upload->path './'.$options['sponsor_imgpath'];
//    if (!($upload->process_upload($vbulletin->GPC['img_file']))){
//        eval(standard_error(fetch_error('there_were_errors_encountered_with_your_upload_x', $upload->fetch_error())));
//    } 
    
        
$sql "INSERT INTO  `" TABLE_PREFIX "sponsors`
                (`title` , `url` , `image` , `description`, `inactive`, `img_file`) 
                VALUES (
                '" 
$db->escape_string($vbulletin->GPC['title']) . "',
                '" 
$db->escape_string($vbulletin->GPC['url']) . "',
                '" 
$db->escape_string($vbulletin->GPC['image']) . "',
                '" 
$db->escape_string($vbulletin->GPC['description']) . "',
                '" 
$db->escape_string($vbulletin->GPC['inactive']) . "',
                '" 
$upload->process_upload($vbulletin->GPC['img_file'] . "'
                        )"
);

$vbulletin->db->query_write($sql);
print_cp_message('Sponsor Added.''sponsors.php'5);
    } 

EDIT: Fixed previous error, new problem.

When I click submit, I get the following error:
Code:

Database error in vBulletin 3.6.8:

Invalid SQL:
INSERT INTO  `sponsors`
                                (`title` , `url` , `image` , `description`, `inactive`, `img_file`)
                                VALUES (
                                'Download Now',
                                'www.download.com',
                                '',
                                'blah blah blah again',
                                '0',
                                ';

MySQL Error  : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 9
Error Number : 1064

Thanks in advance
Steve :)

calorie 01-24-2008 05:39 AM

Missing quote, see below:
Code:

INSERT INTO  `sponsors`
                                (`title` , `url` , `image` , `description`, `inactive`, `img_file`)
                                VALUES (
                                'Download Now',
                                'www.download.com',
                                '',
                                'blah blah blah again',
                                '0',
>>>>>>                                ';


Mythotical 01-24-2008 02:19 PM

I don't see how I'm missing a quote. Very stange.

--------------- Added [DATE]1201192811[/DATE] at [TIME]1201192811[/TIME] ---------------

Found the problem, had to switch this line:
PHP Code:

'" . $upload->process_upload($vbulletin->GPC['img_file'] . "' 

To this:
PHP Code:

'" . $upload->process_upload($vbulletin->GPC['img_file']) . "' 

--------------- Added [DATE]1201192853[/DATE] at [TIME]1201192853[/TIME] ---------------

Still there is a problem, when it goes to upload, seems it doesn't even try to upload or anything.

Lynne 01-24-2008 02:47 PM

You may want to double-check your code for the upload path. I don't think you want to say:
$upload->path = './'.$options['sponsor_imgpath'];

I think you need to add something in there:
$upload->path = './'.$vbulletin->options['sponsor_imgpath'];

?? Maybe?

I had to play with upload code for the torrents on my site. I found it very frustrating because the way I did it, it would not spit out errors to me on the screen. I keep thinking I should rewrite it, but I haven't gotten around to it.

Mythotical 01-24-2008 07:01 PM

Lynne, that is incorrect, I have my own settings, I am not using vBulletin's built in settings stuff. I did my own settings table, settings page, etc so its easier for upgrading and uninstalling.

Thats not the problem, not sure what is but I'm gonna have to do the file upload stand alone and go from there.

Mythotical 01-29-2008 04:28 AM

Almost 5 days have passed and not another response. Can anyone help me get this upload stuff to work?

Dismounted 01-29-2008 05:11 AM

PHP Code:

print_r($vbulletin->GPC['img_file']); 

Make sure it actually has data in it.

Mythotical 01-29-2008 05:36 AM

LOL, I should have thought to do that, thats what happens when you have alot on your mind and too tired to think.

--------------- Added [DATE]1201592290[/DATE] at [TIME]1201592290[/TIME] ---------------

Dismounted: This is what print_r outputs:
Code:

Array ( )
--------------- Added [DATE]1201592548[/DATE] at [TIME]1201592548[/TIME] ---------------

BTW, here is the code for my admin page that has the browse file field.

PHP Code:

// Add Sponsor
if ($_REQUEST['do'] == 'add')
{
print_form_header("sponsors""saved""false""true""add_entry""90%""""true""post");
print_table_header("Add Sponsor");
print_input_row("Title""title"$vbulletin->GPC['title'], $htmlise true$size 35$maxlength 100$direction ''$inputclass false);
print_input_row("URL""url"$vbulletin->GPC['url'], $htmlise true$size 35$maxlength 100$direction ''$inputclass false);
print_input_row("Image""image"$vbulletin->GPC['image'], $htmlise true$size 35$maxlength 100$direction ''$inputclass false);
print_input_row("Description""description"$vbulletin->GPC['description'], $htmlise true$size 35$maxlength 100$direction ''$inputclass false);
print_radio_row('Suspended''inactive', array(=> 'No'=> 'Yes'), $vbulletin->GPC['inactive']);
echo 
'<tr><td class="alt2">Image File</td><td class="alt2"><input type="file" name="img_file" /></td></tr>';
print_submit_row("Add Sponsor");
print_table_footer();  
}

if(
$_REQUEST['do'] == 'saved')
    {    
    
$upload = new vB_Upload_Image($vbulletin);
    
$upload->image =& vB_Image::fetch_library($vbulletin);
    
$upload->path './'.$options['sponsor_imgpath'];
//    if (!($upload->process_upload($vbulletin->GPC['img_file']))){
//        eval(standard_error(fetch_error('there_were_errors_encountered_with_your_upload_x', $upload->fetch_error())));
//    } 
  
        
$sql "INSERT INTO  `" TABLE_PREFIX "sponsors`
                (`title` , `url` , `image` , `description`, `inactive`, `img_file`) 
                VALUES (
                '" 
$db->escape_string($vbulletin->GPC['title']) . "',
                '" 
$db->escape_string($vbulletin->GPC['url']) . "',
                '" 
$db->escape_string($vbulletin->GPC['image']) . "',
                '" 
$db->escape_string($vbulletin->GPC['description']) . "',
                '" 
$db->escape_string($vbulletin->GPC['inactive']) . "',
                '" 
$vbulletin->GPC['img_file'] . "'
                        )"
;
print_r($vbulletin->GPC['img_file']);
$vbulletin->db->query_write($sql);
print_cp_message('Sponsor Added.''sponsors.php'5);
    } 


Dismounted 01-29-2008 08:18 AM

If it's empty, it means that there's (obviously) no data to insert in the first place. Have you actually cleaned it with the cleaner? Because if you haven't, there's no way it'll magically appear in the GPC array.

Mythotical 01-29-2008 01:50 PM

Dismounted: Here is my GPC array.
PHP Code:

$vbulletin->input->clean_array_gpc('r', array(
            
'sid'                  => TYPE_INT,
            
'title'                  => TYPE_STR,
            
'url'                  => TYPE_STR,
            
'image'                  => TYPE_STR,
            
'description'          => TYPE_STR,
            
'sclicks'              => TYPE_STR,
            
'inactive'              => TYPE_STR,
            
'img_type'              => TYPE_STR,
            
'img_file'              => TYPE_FILE
        
)); 

As you can see I have img_file in there. So to answer your question, yes I have cleaned it.


All times are GMT. The time now is 10:38 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.01095 seconds
  • Memory Usage 1,803KB
  • 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
  • (6)bbcode_php_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