vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Writing to a file (https://vborg.vbsupport.ru/showthread.php?t=249511)

mishwar222 08-29-2010 03:24 AM

Writing to a file
 
Hello there,

I am trying to write a task in php. In the end of the task, I need to write to a file called (flag.txt) which resides on my server. So far I couldn’t make the code write to that file. I tried many ways but it doesn’t work.
My code:

<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}

//the task code here

// now in the end I want to write to the file
$myFile = "XXXXXXXXXXXX/flag.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "TRUE";
fwrite($fh, $stringData);
fclose($fh);
?>

The flag.txt permissions is 644, and the writing to a file code works out the vb, but when i put them in the task code they do work.

Thank you for the help.

Jaxel 08-29-2010 05:10 AM

flag.txt should be 777

mishwar222 08-29-2010 06:00 AM

Quote:

Originally Posted by Jaxel (Post 2090964)
flag.txt should be 777

Thank you for your response. Actually I tried it 777 and every combination that i can think of, and it didn't work. If i run the script file outside the vbulletin folder it works very well with just 644. Any other ideas?

Boofo 08-29-2010 06:28 AM

Change:

fopen($myFile, 'a')

to:

fopen($myFile, 'w')

mishwar222 08-29-2010 06:34 AM

Quote:

Originally Posted by Boofo (Post 2090978)
Change:

fopen($myFile, 'a')

to:

fopen($myFile, 'w')

Thank you for the response. I did and it did not work.

Boofo 08-29-2010 06:58 AM

Are you getting any errors at all when you run the code?

mishwar222 08-29-2010 07:21 AM

No, error message, but when I tried another function:

echo file_put_contents(""XXXXXXXXXXXX/flag.txt","Hello World. Testing!");
i got this error message:

"
Warning: file_put_contents() [function.file-put-contents]: Only 0 of 5 bytes written, possibly out of free disk space in [path]/includes/cron/test.php on line 10

done"

Boofo 08-29-2010 07:40 AM

You have double quotes at the beginning of this line. That might be the cause of your error.

""XXXXXXXXXXXX

What are you using for the path? It should be like this:

/home/yourname/public_html/forums

mishwar222 08-29-2010 07:57 AM

Sorry for the typing error. Actually in the original code there was no double quotes.
I am using this path:

"http://Mydomain.com/forum/includes/cron/flag.txt"

Is it correct?

Also somebody said to clear the tmp folder in the server.

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

I changed the path and it works! I will try it with other function as well and see.

Thank you very much Boofo, and Jaxel.


All times are GMT. The time now is 01:07 AM.

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.01154 seconds
  • Memory Usage 1,725KB
  • 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
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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