So I'm writing an XML file in php with fopen/fwrite/fclose and then attempting to save that information into a MySQL database BLOB field; however, I'm running into an issue where after saving the information into MySQL, all the file contains is "Resource id #33" and none of the information that I was trying to save.
$blahXMLFile = fopen($_POST['scenBlahNewName'].".xml","wb");
fwrite($blahXMLFile, "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>");
fwrite($blahXMLFile, "<Blah>");
fwrite($blahXMLFile, "<Name>");
fwrite($blahXMLFile, $_POST['scenBlahNewName']);
fwrite($blahXMLFile, "</Name>");
fwrite($blahXMLFile, "</Blah>");
fclose($blahXMLFile);
$sql = "INSERT INTO blah (xmlFile)
VALUES ('$blahXMLFile');";
if($conn->query($sql) === TRUE) {
} else { echo "<script>alert('Error: " . $sql . "<br>" . $conn->error . "');</script>";
echo "Error: " . $sql . "<br>" . $conn->error;
} //end else
And then after that I take the $blahXMLFile php variable and try to save it in the BLOB field in my MYSQL database and "Resource id #33" is all that's in the file. This is also the case if I use javascript to alert the php variable.
What am I missing?
EDIT: Trying to use fread here correctly based off of a comment:
$blahXMLResource = fopen($_POST['scenBlahNewName'].".xml","w");
$blahXMLFile = fread($blahXMLResource, filesize($_POST['scenBlahNewName'].".xml"));
Because that isn't saving a file at all anymore.