Creating a text file

I am having problems on a server I subscribe to for my domain.

The following is displayed …
[size=8pt]
Folder permissions = 0777

Warning: fopen(D:\probowluk.co.uk\wwwrootformdata/Contact_data.txt) [function.fopen.php]: failed to open stream: No such file or directory in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 94

Warning: fwrite(): supplied argument is not a valid stream resource in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 98

Warning: fflush(): supplied argument is not a valid stream resource in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 99

Warning: fclose(): supplied argument is not a valid stream resource in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 105[/size]

The folder (formdata/) appears to have full permissions, yet the file Contact_data.txt is not being created by fopen

Here is my coding … Any suggestions ? ;D

[php]if ( ($cError == “”) OR ($cError == NULL) )
{
$file_record = $_POST[‘cFname’] . “¬” . $_POST[‘cSname’] . “¬”;
$file_record .= $_POST[‘cMail’] . “¬” . “…”;
$file_record .= $_POST[‘cTxt’] . “¬”;
$file_record .= “\r\n”;
$file_record .= “++++++++++++++++++++++++++++++++++++++” . “\r\n” . “\r\n”;

$RootName = $_SERVER['DOCUMENT_ROOT'];
$FolderName = "formdata/"; 	
$dateYmd = date('Ymd');
$FileName = "Contact_data.txt";
// $FileName = $dateYmd . "_Contact.txt";  

$Fperms = fileperms($FolderName);
echo "Folder permissions = "; 
echo substr(sprintf('%o', $Fperms), -4) . "<br />"; 


// $file_name = $FolderName . $FileName; 
$file_name = $RootName . $FolderName . $FileName; 
echo $_SERVER['DOCUMENT_ROOT'];
//echo $file_name;	

$open_file = fopen($file_name, "a+");

//if (flock($open_file, LOCK_EX)) {   // acquire an exclusive lock
   // ftruncate($open_file, 0);     // truncate file
   fwrite($open_file, $file_record);
   fflush($open_file);             // flush output before releasing the lock
//   flock($open_file, LOCK_UN);     // release the lock
//} else {
//   echo "Couldn't get the lock!";
//};
		
fclose($open_file); 
// $cError = ""; // 
// header("Location: Contact_Done.php");  // 

}

?>[/php]

Your server path is incorrect. You are missing a slash in your file path

Look closely at the path in the error message.

D:\probowluk.co.uk\wwwrootformdata/Contact_data.txt

It would appear by your path that you are on a windows server so you would need to use a backslash
here: $FolderName = “formdata/”; istead of a forward slash

Correct path would be:

D:\probowluk.co.uk\wwwroot[b][/b]formdata[b][/b]Contact_data.txt

Have made the changes, and have alternatives in the coding, but no luck with fopen

[size=8pt]
[color=black]Folder permissions = 0777[/color]
[color=red]D:\probowluk.co.uk\wwwroot
Contact_data.txt
formdata
formdata\Contact_data.txt
D:\probowluk.co.uk\wwwroot\formdata\Contact_data.txt[/color]

Warning: fopen(D:\probowluk.co.uk\wwwroot\formdata\Contact_data.txt) [function.fopen.php]: failed to open stream: Permission denied in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 103

Warning: fwrite(): supplied argument is not a valid stream resource in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 107

Warning: fflush(): supplied argument is not a valid stream resource in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 108

Warning: fclose(): supplied argument is not a valid stream resource in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 114[/size]

[php]
if ( ($cError == “”) OR ($cError == NULL) )
{
$file_record = $_POST[‘cFname’] . “¬” . $_POST[‘cSname’] . “¬”;
$file_record .= $_POST[‘cMail’] . “¬” . “…”;
$file_record .= $_POST[‘cTxt’] . “¬”;
$file_record .= “\r\n”;
$file_record .= “++++++++++++++++++++++++++++++++++++++” . “\r\n” . “\r\n”;

$RootName = $_SERVER['DOCUMENT_ROOT'];
$FolderName = "formdata"; 	
$FullFolderName = $RootName ."\\" . $FolderName; 
$dateYmd = date('Ymd');
$FileName = "Contact_data.txt";
// $FileName = $dateYmd . "_Contact.txt";  
$File_Name = $FolderName . "\\" . $FileName; 
$FullFileName = $RootName . "\\" . $File_Name; 	

$Fperms = fileperms($FolderName);
echo "Folder permissions = "; 
echo substr(sprintf('%o', $Fperms), -4) . "<br />"; 

echo $_SERVER['DOCUMENT_ROOT'];
echo "<br />"; 
echo $FileName;	
echo "<br />"; 
echo $FolderName;		
echo "<br />"; 
echo $File_Name;	
echo "<br />"; 
echo $FullFileName;		
echo "<br />"; 
	
//$open_file = fopen($File_Name, "a+");
$open_file = fopen($FullFileName, "a+");	

//if (flock($open_file, LOCK_EX)) {   // acquire an exclusive lock
   // ftruncate($open_file, 0);     // truncate file
   fwrite($open_file, $file_record);
   fflush($open_file);             // flush output before releasing the lock
//   flock($open_file, LOCK_UN);     // release the lock
//} else {
//   echo "Couldn't get the lock!";
//};
		
fclose($open_file); 
// $cError = ""; // 
// header("Location: Contact_Done.php");  // 

}
[/php]

Is the folder wwwroot permissions 777?

Yes

fileperms($_SERVER[‘DOCUMENT_ROOT’]) gives 0777

Here’s the latest …

[size=8pt]
wwwroot permissions = 0777
formdata permissions = 0777
Root … D:\probowluk.co.uk\wwwroot
File … Contact_data.txt
Folder … formdata
Short address … formdata\Contact_data.txt
Full address … D:\probowluk.co.uk\wwwroot\formdata\Contact_data.txt

About to open formdata\Contact_data.txt…
Warning: fopen(formdata\Contact_data.txt) [function.fopen.php]: failed to open stream: Permission denied in D:\probowluk.co.uk\wwwroot\Contact_proc.php on line 112
Cant open the file
[/size]

Query … should I use the FULL address (prefixed with DOCUMENT_ROOT) or the SHORT address, and would I still need a left/right slash before the folder name ( \formdata\Contact_data.txt ) :-\

As the error message state, you have a permissions problem. Try actually creating the file Contact_data.txt yourself and tell me what happens. If you want to jump start this PM me a login so I can work on it directly where it sits. I will be able to fix it in a jif.

Create a temporary login for me that you can delete as soon as I am done.

IMPORTANT! I forgot to ask you, who owns the file? root? joeuser?

I have logged into your server and created a simple write test file.

The problem is with your web host. They have restricted your permissions. You need to contact them.

Any reason you need to be on a Windows server?

Sponsor our Newsletter | Privacy Policy | Terms of Service