Page 1 of 1

Writing to file

Posted: Tue Sep 09, 2003 11:06 am
by HuggyBear
I've been making this bit of .php to write variables passed from a form to a file on our web hosting server. For some reason, I can't ever seem to find the file even though I think everything is in line.

Feel free to make some suggestions...

Code: Select all

<?

                            //  VARIABLES  from FORM  //

$first=$_POST&#1111;'firstname'];
$last=$_POST&#1111;'lastname'];
$sitename=$_POST&#1111;'client'];
$email=$_POST&#1111;'adress'];
$sitetype=$_POST&#1111;'group'];
$sitenum=$_POST&#1111;'sites'];
$doctors=$_POST&#1111;'doctors'];
$ris1=$_POST&#1111;'RIS1'];
$ris2=$_POST&#1111;'RIS2'];
$ris3=$_POST&#1111;'RIS3'];
$location=$_POST&#1111;'location'];

                                  // MAKE FILE //

$data&#1111;"1"]=$name;
$data&#1111;"2"]=$email;
$data&#1111;"3"]=$sitename;
$data&#1111;"4"]=$sitetype;
$data&#1111;"5"]=$sitenum;
$data&#1111;"6"]=$doctors;
$data&#1111;"7"]=$location;
$data&#1111;"8"]=$ris1;
$data&#1111;"9"]=$ris2;
$data&#1111;"10"]=$ris3;

$data1=serialize($data);
$path="/tmp/client.txt";

if(is_writable ("$path")) 
&#123; 
  $file=fopen($path, "w") or die("The File $path could not be opened"); 
  fwrite($file, $data1); 
  fclose($file); 
&#125; 

if(is_readable ($path))
&#123; 
  chmod ($path, 0660); 
  $file=fopen($path, "w") or die("You frigg'n idiot. Quit now!");  
  fwrite($file, $data1); 
  echo "true";
fclose($file); 
&#125; 

?>
Every time I run the script I get the "true" echo for readable...

So that's about all I know. Please help.

Thanks

Posted: Tue Sep 09, 2003 11:19 am
by JayBird
is this line

Code: Select all

$path="/tmp/client.txt";
the full server path to the file you are wanting to write to/create?

Mark

Posted: Tue Sep 09, 2003 11:22 am
by HuggyBear
Well since it's a web hosting server, I don't know if that is the full path...

I had open_basedir problems and :tmp/ was one of the accept paths....

so I have in my main directory a /tmp (standard set-up for the hosting service) and I also have a /tmp in the directory where the .php resides...

Posted: Tue Sep 09, 2003 11:25 am
by JayBird
run this script on your server to get the full server path

Code: Select all

<?

echo $_SERVER["DOCUMENT_ROOT"];

?>
Mark

Posted: Tue Sep 09, 2003 11:28 am
by HuggyBear
I get /home/phyque2/public_html...but I have a /tmp in /public_html is the thing... it think that would be right..

Like your sig btw... :D

Posted: Tue Sep 09, 2003 11:31 am
by JayBird
change

Code: Select all

$path="/tmp/client.txt";
to

Code: Select all

$path="/home/phyque2/public_html/tmp/client.txt";
That should do it ;)

Mark

Posted: Tue Sep 09, 2003 11:39 am
by HuggyBear
Bah...this crap is going to drive me crazy.....

No file showed up there dangit....

Posted: Tue Sep 09, 2003 12:02 pm
by JayBird
does client.txt already exist?

if not if(is_writable ("$path")) will not evaluate to true!

try creating a blank txt file in the tmp directory.

Mark

Posted: Tue Sep 09, 2003 12:10 pm
by Bizwala
As Mark says above,

You need to have the file clients.txt on the directory. If you have ssh access simply type touch clients.txt in the /tmp directory and make sure it's permissions are writable. Then run the script, that should work. Also make sure that /tmp is a writable directory as well.

This looks like a permission error.

Lani

Posted: Tue Sep 09, 2003 12:42 pm
by HuggyBear
Check and Check... I made sure it was a writable .txt and I made sure the dir was writable... to no avail.

Ryan

Posted: Tue Sep 09, 2003 12:58 pm
by Bizwala
I just ran the code on my server and it works.

In order to make it work I had to comment out line 42 chmod() line then change permissions on client.txt.

What I am suspecting is apache cannot write to /tmp why not try changing $path to "client.txt" or making a new directory under public_html and placing it there?

Lani

Posted: Tue Sep 09, 2003 2:03 pm
by HuggyBear
Well, it must be some settings on the server. I'm going to try to talk to those guys to see what they recommend.

Thanks for the help!