vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   !file_exists help (https://vborg.vbsupport.ru/showthread.php?t=289430)

TheSupportForum 10-22-2012 12:13 AM

!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

kpmedia 10-22-2012 04:05 AM

Quote:

they work in some ways but not 100%
What does this mean? Explain in more details how it works/fails.

TheSupportForum 10-22-2012 05:08 AM

Quote:

Originally Posted by kpmedia (Post 2374966)
What does this mean? Explain in more details how it works/fails.

if file does not exist create this file using these variables simple

kh99 10-22-2012 09:46 AM

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

TheSupportForum 10-22-2012 10:18 AM

Quote:

Originally Posted by kh99 (Post 2375019)
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

kh99 10-22-2012 10:29 AM

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.

TheSupportForum 10-22-2012 11:21 AM

Quote:

Originally Posted by kh99 (Post 2375027)
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


All times are GMT. The time now is 10:21 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.01516 seconds
  • Memory Usage 1,739KB
  • 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
  • (4)bbcode_code_printable
  • (2)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete