File Path problem in voting script for PHP polls

Thanks in advance for any help.

I have a Vote_Polling script that works just perfect as long as the script is in the same directory as the webpage that the poll is located on. However, I want to use the poll sitewide, regardless of directory structure, and have it read/write to the same Polling_Results.txt file no matter where the poll is used from.

My script reads the Polling_Results.txt file fine, without respect to directory structure when I use the full HTTP://… path information. But he problem I am having is that it will not write the voted result to the Polling_Results.txt file when it is in a different directory. I tried making the file read/write/execute globally, to no avail. The error message I receive involves the fopen, fputs, and fclose lines. Can you tell me what I need to change in order to fix the problem?
[php]
//insert votes to txt file
$insertvote = $yes."||".$no;
$fp = fopen($filename,“w”);
fputs($fp,$insertvote);
fclose($fp);
?>
[/php]

Here is the full contents of that script file:
[php]

<?php $vote = $_REQUEST['vote']; //get content of textfile $filename = "http://www.MYWEBSITE.com/polls/poll_result.txt"; $content = file($filename); //put content in array $array = explode("||", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 0) { $yes = $yes + 1; } if ($vote == 1) { $no = $no + 1; } //insert votes to txt file $insertvote = $yes."||".$no; $fp = fopen($filename,"w"); fputs($fp,$insertvote); fclose($fp); ?>

Result:

Yes: <?php echo(100*round($yes/($no+$yes),2)); ?>%
No: <?php echo(100*round($no/($no+$yes),2)); ?>%

[/php]

Thank you again for any assistance on this matter

Sponsor our Newsletter | Privacy Policy | Terms of Service