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 08-29-2010, 03:24 AM
mishwar222 mishwar222 is offline
 
Join Date: May 2010
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 08-29-2010, 05:10 AM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

flag.txt should be 777
Reply With Quote
  #3  
Old 08-29-2010, 06:00 AM
mishwar222 mishwar222 is offline
 
Join Date: May 2010
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jaxel View Post
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?
Reply With Quote
  #4  
Old 08-29-2010, 06:28 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Change:

fopen($myFile, 'a')

to:

fopen($myFile, 'w')
Reply With Quote
  #5  
Old 08-29-2010, 06:34 AM
mishwar222 mishwar222 is offline
 
Join Date: May 2010
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Boofo View Post
Change:

fopen($myFile, 'a')

to:

fopen($myFile, 'w')
Thank you for the response. I did and it did not work.
Reply With Quote
  #6  
Old 08-29-2010, 06:58 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you getting any errors at all when you run the code?
Reply With Quote
  #7  
Old 08-29-2010, 07:21 AM
mishwar222 mishwar222 is offline
 
Join Date: May 2010
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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"
Reply With Quote
  #8  
Old 08-29-2010, 07:40 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #9  
Old 08-29-2010, 07:57 AM
mishwar222 mishwar222 is offline
 
Join Date: May 2010
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
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 06:18 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.04090 seconds
  • Memory Usage 2,232KB
  • Queries Executed 13 (?)
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
  • (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
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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_postinfo_query
  • fetch_postinfo
  • 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