See, I give users of my website the ability to upload their own PHP / HTML / TXT files to their server, right? ... But I want to get this content without saving it on my server and save the contents to a string or what something else.
Can this be done? ... If not, what should I do to get the contents after the file is saved on my server? ... please help me!
I don't know if this can help, but this is the code that I use to upload custom files.
$allowedExts = array("php", "html", "txt"); $tmp = explode(".", $_FILES["file"]["name"]); $extension = end($tmp); if ((($_FILES["file"]["type"] == "application/octet-stream") || ($_FILES["file"]["type"] == "text/php") || ($_FILES["file"]["type"] == "text/html") || ($_FILES["file"]["type"] == "text/plain")) && ($_FILES["file"]["size"] < 50000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } } else { echo "Invalid file"; }
source share