I have a unity C# program which is uploading a binary file (with some data).
(which is kind of irrelvant but maybe not)
var form = new WWWForm();
byte textarr = Encoding.ASCII.GetBytes("just a sample text to be compressed and sent to server");
string req = "my url";
WWW www = new WWW(req,form);
$binaridata = ~$_FILES["file"]["name"] (what do i need to do here? tried
$binaryData = file_get_contents($_FILES['file']['tmp_name']); ^^^^^^^^
The file is stored at the path indicated by
name is just the name given by the client and practically irrelevant.
Depending on how you talk to the database and what database, you don't want to read the entire file contents into a variable though. For instance, using Postgres via PDO, you'd do this:
$stmt = $pdo->prepare('INSERT INTO ... VALUES (:file)'); $fh = fopen($_FILES['file']['tmp_name'], 'rb'); $stmt->bindParam(':file', $fh, PDO::PARAM_LOB); $stmt->execute();
The database adapter will read the file as a stream, which is much more economic than saving it in memory. Consult your database adapter's manual.