DataRater Posted August 15, 2008 Share Posted August 15, 2008 All I can put in is the name of the image i.e. 'MissSilver.jpg' In the insert statement 'name' is a varchar for the filename and 'picture' is a blob for the image. Both columns end up with the name 'MissSilver.jpg' in them. How do I store the image? Here is the code <?php require_once 'MySQL5.php'; ?> <head> <title>Load image into database</title> </head> <body> <?php if (isset($_POST['file'])){ $file=$_POST['file']; $YSLink=DBConnection('database'); if(!$YSLink) { echo "Failed to connect to the server"; } $sql=sprintf( "insert into pictures (name,picture)VALUES('%s','%s')", mysqli_real_escape_string($YSLink,$file), mysqli_real_escape_string($YSLink,$file) ); $ResultSet = GetResultOfQuery($YSLink,$sql); if ($ResultSet) { echo "Inserted<br />"; } else{ echo "Not inserted<br />"; } } ?> <?php echo date('l jS \of F Y h:i:s A') ?><br /><br /> <form action='http://testbed' method=POST> <fieldset> <legend>Enter the image</legend> <ol> <li> <label for='file'>File:: </label> <input id='file' name='file' type='file' value='' size=60 maxlength=60/> </li> <input type='SUBMIT' class='submit' value='Submit'/> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/119820-solved-cant-save-image-into-mysql-column/ Share on other sites More sharing options...
DataRater Posted August 15, 2008 Author Share Posted August 15, 2008 I've got a bit further. I've added enctype="multipart/form-data" to <form action='http://yotspace/testbed' method=POST enctype="multipart/form-data"> and then looked in $_FILE and got this 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"]."<br />"; It's returning Upload: MissSilver.jpg Type: image/jpeg Size: 17.546875 Kb Stored in: /tmp/phpeJIigI I'm working on it!!! Link to comment https://forums.phpfreaks.com/topic/119820-solved-cant-save-image-into-mysql-column/#findComment-617299 Share on other sites More sharing options...
DataRater Posted August 15, 2008 Author Share Posted August 15, 2008 It works fine now. Link to comment https://forums.phpfreaks.com/topic/119820-solved-cant-save-image-into-mysql-column/#findComment-617306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.