html - Struggling to display blob image with php -
I am creating a simple website, I want to allow users to upload and change their avatars. Currently I am able to upload images in a mysql database, such as code stored in the form of blobs:
// connected to DB, userID has $ image = $ FILES ['fileToUpload'] ['tmp_name']; $ Fp = fopen ($ image, 'r'); $ Content = fread ($ fp, filesize ($ image)); $ Content = addslashes ($ content); Fclose ($ FP); $ Sql = "Update tbUsers SET ProfileVersion = '" $ Content "'UserID =". User ID; $ Result = mysql_query ($ sql) or die (mysql_error ());
After uploading files when I download files from phpmyadmin, they are saved as .bin files, but can be viewed normally. I'm not sure whether this is correct or not my image is displayed as follows:
HTML:
& lt ;? Php echo '& lt; Img src = "showPic.php? Q = '. $ _SESSION [' Profile ']'" / & gt; ? & Gt;
PHP:
if (! $ _ GET ['profile']) & amp; amp; is_numeric ($ _GET ['profile' ])) {$ Con = mysql_connect ("localhost", "root", ""); $ Mysql_select_db ("projectDB"); $ Sql = "Select tbUsers from profile image where user id =". $ _GET ['Profile']; $ Result = mysql_query ($ sql) or die (mysql_error ()); Header ('content type: image / jpeg'); $ Line = mysql_fetch_object ($ result); Echo ['image_data'] per line; }
I'm sure if I'm trying to display the image correctly, then any help (correction / alternate solution) will be appreciated :)
You can:
if (! Below ($ _ GET [ 'Profile']) and; & amp; amp; is_numeric ($ _GET ['profiles'])) {$ con = mysql_connect ("localhost", "root", ""); $ Mysql_select_db ("projectDB"); $ Sql = "Select tbUsers from profile image where user id =". $ _GET ['Profile']; $ Result = mysql_query ($ sql) or die (mysql_error ()); $ Content = mysql_result ($ result, 0, "file_content"); $ Name = mysql_result ($ result, 0, "file_name"); $ Type = mysql_result ($ result, 0, "file_type"); $ Size = mysql_result ($ result, 0, "file_size"); Header ("content-type: $ type");
Note: You should have these columns in your table, where you save your blob data
file_name = to save the file name
Save the file type $ _ files ['file'] ['name']
file_type =
$ _ files [ 'File'] [File type to save file size
$ _ files ['file'] ['size']
Comments
Post a Comment