When debugging a small program that uploads files and stores them in the database, problems always occur. Ask the experts here!

Source: Internet
Author: User
Tags mysql connect
When debugging a small program that uploads files and stores them in the database, problems always occur. Ask the experts here! In fact, this function should be very simple. I can see a program on the Internet and debug it myself, but there are unexpected errors. please kindly advise.

Html front-end code:
 


Php back-end code:
 


The database is onlytest, the table name is file, and several keywords are id, contents, type, name, and size. The settings are as follows:


Reply to discussion (solution)

What is the error message?

$ Why does file_data use LONGBLOB fields for storage?

There is no error message, but "failed" is always reported. I checked the database and did not store the data in the database.

Considering that I may use a large document or file for testing, the longblob type is used.

This problem occurs when uploading small GIF images, but large files such as jpg and word cannot be stored.

What is the maximum size of Upload allowed for your configuration?

Yes, it may be this problem. I recently found that a system fixed variable represents this problem. how can I modify this variable?


What is the maximum size of Upload allowed for your configuration?

Print_r ($ _ FILES); there is no value when uploading large FILES,
In addition, echo mysqli_error ($ conn); is there an error?

I found in php. ini that upload_max_filesize = 2 M, max_file_uploads = 20
It does not look wrong either.

What is the maximum size of Upload allowed for your configuration?

After uploading an image of 74K, the image is not saved in the database and "failed" is returned ". In php. ini, the maximum file upload limit is 2 MB.
What happened?

Added print_r ($ _ FILES); echo mysqli_error ($ conn) according to your suggestion );
The result is:


No other error information (my browser error information is displayed normally ). What happened to this?
Print_r ($ _ FILES); there is no value when uploading large FILES,
In addition, echo mysqli_error ($ conn); is there an error?

What are SQL statements that can be printed?

Echo mysqli_error ($ conn); this sentence is added under mysqli_quey.

I changed the position of the command for printing error messages and put it at the end. The command is as follows:
Echo"
";
Print_r ($ _ FILES );
Echo"
";
Echo mysqli_error ($ conn );
Echo"
";

All printed information is:

Failed!
Array ([file] => Array ([name] => photo.jpg [type] => image/jpeg [tmp_name] => C: \ Windows \ Temp \ phpA968.tmp [error] => 0 [size] => 76201 ))
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.) 10 .) -, 3: J> 36F7,-@ WAFLNRSR2> ZaZP 'jqro limit quota' at line 1

Also, I uploaded a large file, and echo $ SQL showed a long content, which is not displayed here.


Looks like insert into onlytest. file (contents, type, name, size) values ('$ file_data', '$ file_type', '$ file_name', $ file_size)
What's wrong with this sentence?
What are SQL statements that can be printed?

Print_r ($ _ FILES); there is no value when uploading large FILES,
In addition, echo mysqli_error ($ conn); is there an error?

I 'd like to print out all the commands and displays. let's wait for some advice.

Echo"
";
Print_r ($ _ FILES );
Echo"
";
Echo mysqli_error ($ conn );
Echo"
";
Echo $ SQL;
Mysqli_close ($ conn );

Error message:

Filter it out. Add $ file_data to the mysql_escape_string function.

Not to mention, this trick is really useful, and it is a success. Only mysql_escape_string can be used for mysql_real_escape_string.

I made another program and downloaded it from the database.

But why? Can you explain it?

Filter it out. Add $ file_data to the mysql_escape_string function.

I searched for the information and learned why. Thank you.

Close the post.

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.