I am looking for a way to allow for file uploads but rather than writing the file to disk on the web-server, I would like to store the binary contents in a variable. I've found a simple example to actually perform uploads but I cannot find a way to prevent writing to file and instead keep it in memory.
Is it possible to do this and if so how?
<?php
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
If you only need the uploaded file for php runtime then
$uploadfile = file_get_contents($_FILES['userfile']['tmp_name']);
Later if you need to store it on MySQL DB, you can always do 'addslashes()' to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With