Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-22-2015, 04:29 PM
Mickie D Mickie D is offline
 
Join Date: Jun 2002
Posts: 430
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP code problem

Hi all,

I have an issue with this code. What seems to happen is when it creates the file from the chunked upload it stores it in

/temp/

It should join all the parts then store it here

/temp/USERNAME/


PHP Code:
    $temp_dir '/temp/'.$vbulletin->userinfo['username'].'/'.$_POST['resumableIdentifier'];
    
$dest_file $temp_dir.'/'.$_POST['resumableFilename'].'.part'.$_POST['resumableChunkNumber'];

    
// create the temporary directory
    
if (!is_dir($temp_dir)) {
        
mkdir($temp_dir0777true);
    } 

this is part of the function that works with it.

PHP Code:
    if ($total_files $chunkSize >=  ($totalSize $chunkSize 1)) {

        
// create the final destination file 
        
if (($fp fopen('/temp/'.$vbulletin->userinfo['username'].'/'.$fileName'w')) !== false) {
            
            
fclose($fp);
        } else {
            
_log('cannot create the destination file');
            return 
false;
        }

        
// rename the temporary directory (to avoid access from other 
        // concurrent chunks uploads) and than delete it
        
if (rename($temp_dir$temp_dir.'_UNUSED')) {
            
rrmdir($temp_dir.'_UNUSED');
        } else {
            
rrmdir($temp_dir);
        }
    } 
Reply With Quote
  #2  
Old 05-22-2015, 04:49 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where is that code going (if it's a plugin, which hook)? You might need a
PHP Code:
global $vbulletin
statement in your code.
Reply With Quote
  #3  
Old 05-22-2015, 04:52 PM
Mickie D Mickie D is offline
 
Join Date: Jun 2002
Posts: 430
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi again KH99

This is in a custom php page, it calls global at the beginning...

I even wrote out an template register variable that calls $temp_dir

and it outputs

/temp/Mick/

But I am not sure why its writing the file to /temp/ and NOT /temp/Mick

PHP Code:

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php'); 
Thank you.
Reply With Quote
  #4  
Old 05-22-2015, 04:59 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, so the part that's missing is $fileName. I don't see that being set anywhere in the code you posted.
Reply With Quote
  #5  
Old 05-22-2015, 05:01 PM
Mickie D Mickie D is offline
 
Join Date: Jun 2002
Posts: 430
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ahh sorry,

I missed the function

the function
PHP Code:
function createFileFromChunks($temp_dir$file$chunkSize)

    
// check that all the parts are present
    // the size of the last part is between chunkSize and 2*$chunkSize
    
if ($total_files $chunkSize >=  ($totalSize $chunkSize 1)) {

        
// create the final destination file 
        
if (($fp fopen('/temp/'.$vbulletin->userinfo['username'].'/'.$fileName'w')) !== false) {
            for (
$i=1$i<=$total_files;)
            }
            
fclose($fp);
        } else {
            
_log('cannot create the destination file');
            return 
false;
        }

        
// rename the temporary directory (to avoid access from other 
        // concurrent chunks uploads) and than delete it
        
if (rename($temp_dir$temp_dir.'_UNUSED')) {
            
rrmdir($temp_dir.'_UNUSED');
        } else {
            
rrmdir($temp_dir);
        }
    }



the code
PHP Code:
if (!empty($_FILES)) foreach ($_FILES as $file) {

    
// check the error status
    
if ($file['error'] != 0) {
        
_log('error '.$file['error'].' in file '.$_POST['resumableFilename']);
        continue;
    }

    
// init the destination file (format <filename.ext>.part<#chunk>
    // the file is stored in a temporary directory
    
$temp_dir '/temp/'.$vbulletin->userinfo['username'].'/'.$_POST['resumableIdentifier'];
    
$dest_file $temp_dir.'/'.$_POST['resumableFilename'].'.part'.$_POST['resumableChunkNumber':
                
                
    }

    

Reply With Quote
  #6  
Old 05-22-2015, 06:29 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's because the $vbulletin variable can not be reached inside the function you use.
You have to use "global $vbulletin;" inside of the function or pass the $vbulletin variable as a 5th argument to the function.
Reply With Quote
3 благодарности(ей) от:
kh99, Lynne, MarkFL
  #7  
Old 05-22-2015, 07:58 PM
Mickie D Mickie D is offline
 
Join Date: Jun 2002
Posts: 430
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave View Post
It's because the $vbulletin variable can not be reached inside the function you use.
You have to use "global $vbulletin;" inside of the function or pass the $vbulletin variable as a 5th argument to the function.
Excellent Dave... Thank you very much. That worked perfect

Is that the same with all functions? If I want to use vbbulletin variables

Cheers
Reply With Quote
  #8  
Old 05-23-2015, 06:14 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, that's always the case, not only in vB. Global variables are never available inside functions in PHP, you always need to pull them in like that.
Reply With Quote
  #9  
Old 06-01-2015, 10:02 AM
Mickie D Mickie D is offline
 
Join Date: Jun 2002
Posts: 430
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
Yes, that's always the case, not only in vB. Global variables are never available inside functions in PHP, you always need to pull them in like that.
Thanks been doing allot of reading - bought a few books and found out quite a bit already!

Thank you all for the support

Mick
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:45 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.04489 seconds
  • Memory Usage 2,277KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (3)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete