Search code examples
phpfileserver-sidefile-writing

File-writing script just creates an empty file named "0"


When I write a file using PHP,

<?php
    header('Access-Control-Allow-Headers: *');
    $texttowrite = $_POST['articletext'];
    $title = $_POST['title'];
    $name = $_POST['name'];
    // Illegal characters on Unix and Linux or any *nix server
    $illegal = array(" ", "?", "/", "\\", "*", "|", "<", ">", '"');
    // Legal characters
    $legal = array("-", "_", "_", "_", "_", "_", "_", "_", "_");
    // Replace it!
    $newtitle = str_replace($illegal, $legal, $title);
    $newname = str_replace($illegal, $legal, $name);
    $filename = "content/" + $newtitle + "-" + $newname;
    $myfile = fopen($filename, "w") or die("Unable to open file!");
    fwrite($myfile, $texttowrite);
?>

note: this program is supposed to read output and a file name from POST form data and write it to a server.

it just creates a file called "0" in the root directory of the server's file system. Is there anything that's going wrong?

No errors were generated by the compiler.


Solution

  • String concatenation in PHP is ., not +.