Created
May 20, 2012 18:35
-
-
Save haric/2759064 to your computer and use it in GitHub Desktop.
Upload file to db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ob_start(); | |
| ini_set ("display_errors", 1); | |
| if (isset($_POST["submit"])) { | |
| $fileName = $_FILES['file']['name']; | |
| $tmpName = $_FILES['file']['tmp_name']; | |
| $fileSize = $_FILES['file']['size']; | |
| $fileType = $_FILES['file']['type']; | |
| $fp = fopen($tmpName, 'r'); | |
| $content = fread($fp, filesize($tmpName)); | |
| $content = addslashes($content); | |
| fclose($fp); | |
| if(!get_magic_quotes_gpc()) | |
| { | |
| $fileName = addslashes($fileName); | |
| } | |
| $c = mysqli_connect("localhost" , "root", "", "mcdb"); | |
| $sql = "REPLACE INTO photo (name, size, type, content ) VALUES('$fileName', '$fileSize', '$fileType', '$content')"; | |
| $rc = mysqli_query($c, $sql); | |
| mysqli_close($c); | |
| ob_end_flush(); | |
| ini_set("display_errors", 0); | |
| exit(); | |
| } | |
| ?> | |
| <form method="POST" enctype="multipart/form-data"> | |
| <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> | |
| <label for="file">Filename:</label> | |
| <input type="file" name="file" id="file" /> | |
| <br /> | |
| <input type="submit" name="submit" value="Submit" /> | |
| </form> | |
| <?php | |
| ob_end_flush(); | |
| ini_set("display_errors", 0); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment