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

Reply
 
Thread Tools Display Modes
  #1  
Old 10-22-2012, 01:13 AM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default !file_exists help

Hi guys

im trying to have a file created if not exist, so far i have

PHP Code:
$ourFileName "$vbulletin->options['thefilename']";
 if (!
file_exists($vbulletin->options['thefilename'] . '$ourFileName'))
{
$filename '$ourFileName';

i have also tried

PHP Code:
if (!file_exists($ourFileName)) {
$ourFileName "$vbulletin->options['thefile']";
$ourFileHandle fopen($ourFileName'w') or die("can't open file");
fclose($ourFileHandle);

they work in some ways but not 100%, im not even sure if its the correct format for vbulletin

i know this is not 100% correct but need the variable corrected
Reply With Quote
  #2  
Old 10-22-2012, 05:05 AM
kpmedia's Avatar
kpmedia kpmedia is offline
 
Join Date: Jan 2008
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
they work in some ways but not 100%
What does this mean? Explain in more details how it works/fails.
Reply With Quote
  #3  
Old 10-22-2012, 06:08 AM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kpmedia View Post
What does this mean? Explain in more details how it works/fails.
if file does not exist create this file using these variables simple
Reply With Quote
  #4  
Old 10-22-2012, 10:46 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think this should work:

Code:
$ourFileName = $vbulletin->options['thefile'];
if (!file_exists($ourFileName)) {
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
}

but you probably wouldn't want the "or die()" part because that would leave you with a white page with an error message. You could do something like this:
Code:
$ourFileName = $vbulletin->options['thefile'];
if (!file_exists($ourFileName)) 
{
   $ourFileHandle = fopen($ourFileName, 'w');
   if ($ourFileHandle === FALSE)
   {
      // Do something here to handle error
   }
   else
   {
      fclose($ourFileHandle);
   }
}

Also, using "w" in the fopen call will truncate the file (make it empty), so if you don't want that, use either "r" or "a".
Reply With Quote
  #5  
Old 10-22-2012, 11:18 AM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I think this should work:

Code:
$ourFileName = $vbulletin->options['thefile'];
if (!file_exists($ourFileName)) {
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
}
but you probably wouldn't want the "or die()" part because that would leave you with a white page with an error message. You could do something like this:
Code:
$ourFileName = $vbulletin->options['thefile'];
if (!file_exists($ourFileName)) 
{
   $ourFileHandle = fopen($ourFileName, 'w');
   if ($ourFileHandle === FALSE)
   {
      // Do something here to handle error
   }
   else
   {
      fclose($ourFileHandle);
   }
}
Also, using "w" in the fopen call will truncate the file (make it empty), so if you don't want that, use either "r" or "a".
as long as its writeable its fine, the idea of this $ourFileName is that it shows a log
this worked for the end user but not the admin

what was happening was the following

1) user visited forum
2) if variable was true, it wrote to the $ourFileName
3) but some admins could not create this file automacially
( for me it worked ) for another website ( admin did not work )

i will use the above code to see how today goes with it
Reply With Quote
  #6  
Old 10-22-2012, 11:29 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, the ability to create a file will depend on how the server permissions are set of course. You may have your set up to allow creation of a file anywhere whereas someone else doesn't (really you probably shouldn't allow it in the same directories that your php scripts are in, but I'm not a server config expert or anything). Maybe what you want to do is have an option to specify a directory, then instruct the admin to enter a path that has create permission for whatever user the web server runs as.
Reply With Quote
  #7  
Old 10-22-2012, 12:21 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Well, the ability to create a file will depend on how the server permissions are set of course. You may have your set up to allow creation of a file anywhere whereas someone else doesn't (really you probably shouldn't allow it in the same directories that your php scripts are in, but I'm not a server config expert or anything). Maybe what you want to do is have an option to specify a directory, then instruct the admin to enter a path that has create permission for whatever user the web server runs as.
well the good thing is that this variable is called within a folder acceable to admins
only, this is why the $variable is called to create a file somewhere

plugin : global start
$seeks this file upon a $true value, which allows the $event to be logged

the problem i am having with it is sharing this script which will also create the log in the same manner and folder, but they get the error message upon file creation and i dont

which i am trying to figure out if its and issue with fopen or
if (!file_exists($ourFileName))

which would be a permission issue somewhere on their webserver
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 08:24 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.04070 seconds
  • Memory Usage 2,233KB
  • 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
  • (4)bbcode_code
  • (2)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete