I had written PHP loong time ago. I wrote this simple script but I am getting this error below. I have also added the code. Please help me to find my mistake.
Parse error: syntax error, unexpected '"book.txt"' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\test\index.php on line 11
<?php
print('<pre>');
if(!isset($_FILES['userfile'])){
$fname="book.txt";
$arrayk = explode("\n", file_get_contents($fname));
$num=array_rand($arrayk,1);
print($arrayk[$num]."</br>");
}else{
$uploadedfile = "book.txt"; //this line is giving an error.
$extensions= array("txt");
$file_type=$_FILES['userfile']['type'];
if(in_array($file_ext,$extensions)=== false){
print("extension not allowed, please choose a txt file.");
}else{
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadedfile)) {
print("File is valid, and was successfully uploaded.\n");
} else {
print("Possible file upload attack!\n");
}
}
print("Here is some more debugging info:");
print_r($_FILES);
}
print("</pre>");
?>
<!DOCTYPE html>
<html>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="index.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
</html>
I tried the code I have written. I am guessing there is a problem with my PHP