Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
New person having problems with php and scripting
Old 11-21-2007, 02:12 AM New person having problems with php and scripting
Novice Talker

Posts: 7
Name: steve
Trades: 0
Hi folks, Im new to this web design game, but find it very addictive. I have a website for business purposes and I purchased wysiwyg to make life easier.

So far I have done a couple of things in php, one was set up a password page and login ect, and this worked well.

The other one Im having problems with and my host is telling me the problem lies with me and not them. "more than likely true"

I simply want to be able to read and write from my php page to a txt file. Thats it. I can get my scripting to access and display the files contents on my php page but I cannot get the file to open for editing. I have chmodded the files to 777, but it still wont allow itself to be opened for editing.
Can anyone help us out

Heres the first script which works just fine


<?php
$newline = "<br />";
echo "Php Test 2 Read file".$newline;
echo "Response..".$newline.$newline;
include("yourfile.txt");
?>


the second script doesnt open the file it comes back as per my command
Php write failed


<?php
echo "Php Test 1 Write to yourfile.txt"."<br />";
echo "Response"."<br />"."<br />";
$myFile = "yourfile.txt";
$fh = fopen($myFile, 'w') or die("Php write failed");
$stringData = "Fred Flinstone\n";
fwrite($fh, $stringData);
$stringData = "Daffy Duck\n";
fwrite($fh, $stringData);
fclose($fh);
?>


Ideas, Im pulling my hair out, I know this is pretty basic stuff, but Im not having any success
Thanks
Steve
simso is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-21-2007, 06:38 AM Re: New person having problems with php and scripting
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
If I am not wrong you need to define path to txt file.
define("PATH", "/home/youraccount/");
$myFile = PATH . "yourfile.txt";

or maybe you can use $_SERVER['DOCUMENT_ROOT'];

$myFile = $_SERVER['DOCUMENT_ROOT'] . "/yourfile.txt";

Shivaji
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 11-21-2007, 06:43 AM Re: New person having problems with php and scripting
Novice Talker

Posts: 7
Name: steve
Trades: 0
Yes I did thatas well and it made no difference,

You will also notice that one set of script works but the other doesnt, it fails when it tries to open the file, displaying its contents works fine. Ive chmodded the file to 777, just cant work out what else could be stopping it from being edited and opened.
My server saids its my script and not there hosting
Steve
simso is offline
Reply With Quote
View Public Profile
 
Old 11-21-2007, 07:01 AM Re: New person having problems with php and scripting
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
What is the error reported by PHP when it tries to open / write the file ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-21-2007, 07:12 AM Re: New person having problems with php and scripting
Novice Talker

Posts: 7
Name: steve
Trades: 0
It simply saids as per the script

Php write failed

If you have a look at line 5 it simply closes and throughs me my pre written response. If theres a better way of doing this, Im happy to amend script accordingly, I just dont know enough lingo to be able to do it another way

Steve
simso is offline
Reply With Quote
View Public Profile
 
Old 11-21-2007, 08:09 AM Re: New person having problems with php and scripting
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Then it's not the read that fails, but the file opening....
Are you sure you have the file in the same directory than the script? It could be that.

Try to put an
PHP Code:
error_reporting(E_ALL); 
on top of your script.
It will force PHP engine to output every warning and notices that may be kept silent.



Look for any messages before the fopen, it may report more details about the cause of the error
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 11-21-2007 at 08:21 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-21-2007, 08:20 AM Re: New person having problems with php and scripting
Novice Talker

Posts: 7
Name: steve
Trades: 0
Yep there both in the wwwroot directory, I just inserted that code at the top of the file open script and there was no change in the output, it just simply popped up
Php write failed
Its frustrating, to me it means the file permissions are incorrect, but I login to the server and check permissions and there all 777 for both the txt file and the php file. What else could be stopping the open file option. I tried to see if I could adjust the permissions of the folder wwwroot but it would not allow me to.
Frustrating. Ahhhhhhh
simso is offline
Reply With Quote
View Public Profile
 
Old 11-21-2007, 11:24 AM Re: New person having problems with php and scripting
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Ok, I can confirm you that the problem is not in your script, if you had any doubt.

Now, where are you running this script ?
Windows or Linux/BSD ?
Are you running in sage mode ?

I suspect that the debug might be sent to the site error log, if nothing is displayed when you run it..
Try to put those calls at the top of your file:
PHP Code:
ini_set('display_errors'true);
ini_set('log_errors',true);
ini_set('error_log','php.log');
error_reporting(E_ALL); 
This should display any notices/warnings AND/OR log them to a text file named php.log in the same directory than your script.
Try to place in your "or die()" call an echo of $php_errormsg.
This variable should hold the last error to have occured in the running script too.

I'm sure that if we can have access to PHP log, we will find what the problem is.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 11-21-2007 at 11:28 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-21-2007, 05:59 PM Re: New person having problems with php and scripting
Novice Talker

Posts: 7
Name: steve
Trades: 0
Thanks for the scripting, it worked a treat heres the page printout

Php Test 1 Write to yourfile.txt
Response


Warning: fopen(yourfile.txt) [function.fopen]: failed to open stream: Permission denied in E:\CustomerData\webspaces\webspace_00106423\wwwroo t\alltry.php on line 9
Php write failed

The host now tells me that due to security reasons they dont allow fwrite, I pointed out that they dont allow fopen either, they argued again and I directed them to my page and yes they dont support fopen either. What a bunch of you know whats. 4 days this has gone on for with them telling me its my scripting not there site, it @#$%$##@#$ me off
Thanks for all the comments and definetly thenkyou tripy
Steve
simso is offline
Reply With Quote
View Public Profile
 
Old 11-21-2007, 07:02 PM Re: New person having problems with php and scripting
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
In my opinion, it's plain stupid and just bothering customers than restricting write access.

You can read anything you want, but you cannot write ?
What security measure is this ???

I would be moving my hosting somewhere else...
Anyway, I'm glad you could sort this out.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-21-2007, 07:19 PM Re: New person having problems with php and scripting
Novice Talker

Posts: 7
Name: steve
Trades: 0
Yes I agree, Ive locked into these guys for 1 year with two websites, and I can tell you now not impressed.

Last edited by simso; 11-21-2007 at 07:26 PM..
simso is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to New person having problems with php and scripting
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32966 seconds with 12 queries