Or upload and display of images _ PHP Tutorial

Source: Internet
Author: User
Or the image upload and display problem. Whether the image upload display problem is still the image upload display problem, the improved image still cannot display upload. php: storebinarydata‑sqldatabaseif (isset ($ _ POST [submit]) {$ fo or image upload and display problems



Still, the image cannot be displayed after being improved.

Upload. php:


Store binary data into SQL Database

If (isset ($ _ POST ['submit ']) {
$ Form_description = $ _ POST ['form _ description'];
$ Form_data_name = $ _ FILES ['form _ data'] ['name'];
$ Form_data_size = $ _ FILES ['form _ data'] ['size'];
$ Form_data_type = $ _ FILES ['form _ data'] ['type'];
$ Form_data = $ _ FILES ['form _ data'] ['tmp _ name'];
$ Connect = MYSQL_CONNECT ("localhost", "root", "123") or die ("Unable to connect to MySQL server ");
Mysql_select_db ("db_database18") or die ("Unable to select database ");
$ Data = addslashes (fread (fopen ($ form_data, "r"), filesize ($ form_data )));
$ Result = MYSQL_QUERY ("insert into ccs_image (description, bin_data, filename, filesize, filetype) VALUES ('$ form_description', '$ data',' $ form_data_name ', '$ form_data_size', '$ form_data_type ')");
$ Id = mysql_insert_id ();
Print"

This file has the following Database ID:$ Id";
MYSQL_CLOSE ();
} Else {
?>




}
?>




Imglist. php



$ Connect = MYSQL_CONNECT ("localhost", "root", "123") or die ("Unable to connect to MySQL server ");
Mysql_select_db ("db_database18") or die ("Unable to select database ");
$ Result = mysql_query ("SELECT * FROM ccs_image") or die ("Can't Perform Query ");
While ($ row = mysql_fetch_object ($ result )){
Echo "id." '>
";
}
?>



Show. php

If (isset ($ _ GET ['id']) {
$ Id = $ _ GET ['id'];
$ Connect = MYSQL_CONNECT ("localhost", "root", "sa") or die ("Unable to connect to MySQL server ");
Mysql_select_db ("test") or die ("Unable to select database ");
$ Query = "select bin_data, filetype from ccs_image where id =". $ id;
$ Result = @ MYSQL_QUERY ($ query );
$ Data = @ MYSQL_RESULT ($ result, 0, "bin_data ");
$ Type = @ MYSQL_RESULT ($ result, 0, "filetype ");
Header ("Content-type: $ type ");
Echo $ data;
}
?>

Let me answer




Website construction and solution
Resolved

Website construction and solution
For non-production systems, it is recommended to display all error messages.

Website construction and solution
Why? Share the result...


Upload or image upload display problems. after improvement, the image still cannot be displayed as upload. php: Store binary data into SQL Database if (isset ($ _ POST ['submit ']) {$ fo...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.