Using PHP to write to a server


#1

I keep getting these errors

Warning: fopen("mbrsite/",$pname,".html") [function.fopen]: failed to open stream: Invalid argument in C:Servercompile.php on line 7

Warning: fwrite(): supplied argument is not a valid stream resource in c:servercompile.php on line 11

Warning: fwrite(): supplied argument is not a valid stream resource in C:Servercompile.php on line 12

I suspect the fwrite problem is a result of the file$ being invalid.

[code]<?php
$code = $_POST[“say”];
$pname = $_POST[“name”];

$sname = (’“mbrsite/”,$pname,".html"’);

$file = fopen($sname, ‘a’);

fwrite($file, “
”);
fwrite($file, $code . “
”);

?> [/code]

It uses two fields from the HTML document, the one named “Name” is the actual HTML page name. The other is the HTML code.

I want the HTML page name formatted with .HTML on the end, saved into that directory “mbrsites”.

Any suggestions or help is MUCH appreciated!


#2

Any help with this one?


#3

First I would like to point out the difference between the ’ (Single Quote) and the " (Double Quote).

The Double Quote allows you to embed data, such as from a variable, within a string without special formating (such as concatenating). If you need to use the double quote as part of the string, then it must be escaped with the backslash ( ). Many other things may need to be escapped as well.

The single quote would not allow the variables embedded in the string. Probably the biggest thing to require escaping is the single quote (or apostrophe).

The double quoted string is put through the parser for php and would run slower than the string that was single quoted.

Looking at your $sname assignment, you have it wrong.

with $sname = (’“mbrsite/”,$pname,".html"’);
the value of $sname would be “mbrsite/”,$pname,".html"

Thus that would generate the FIRST warning as I suspect that the LITERAL “mbrsite/”,$pname,".html" is NOT a valid file name.

Next, although this error didn’t show up… It looks like you are on a windows system and the FORWARD SLASH is used on NIX systems as a directory sepeartor. For windows you need to use the BACK SLASH. Unfortunately, this will cause another problem. Since the character is the Escaping character, you will need to escape it. so it would need to be a double back slash

Finally, not sure what you are doing with the commas bewteen the mbrsite $pname and .html sections. If you are trying to concatenate, you need to use the dot as a concatenate

try using:
$sname =“mbrsite”.$pname.".html";