A few problems with uploading a picture project

Source: Internet
Author: User

received a project, is roughly to make a visit to the H5, need to save the user submitted text and photos.

Front-end colleague wrote a demo, I first test in the local environment.
took a few pictures of the hundreds of K test, using my free time to write my own simple API template and file upload class, more than 10 minutes to fix the local code. Directly on the test server.

A series of problems were encountered during test server testing.

  1. Problem: During debugging, the file_put_contents output error is not visible when you use multiple times.
    A: Consulted with the administrator to understand. The original test server FTP is a master-slave, about 10 minutes synchronization.
    Solution: As this test suit is not in our management scope, we have to carefully upload. After all, it may take 19 minutes after uploading to see the results.

  2. Problem: The database corresponding to the test server runs successfully when the INSERT and UPDATE statements are executed, and when the SELECT statement is executed, a "1146 table does not exist" error is reported.
    A: After a preliminary understanding of Google Query, the database is assumed to be a master-slave architecture, and then to the database administrator to confirm. learned that the database is also a master-slave architecture, 10 minutes synchronization, but may be configured with a point of issue, the main library of the table is not synchronized to the library after creation. The INSERT and UPDATE statements are run directly in the main library, so there is no problem, and the SELECT statement reads from the library, resulting in a 1146 error.
    Solution: We also do not have the database management rights, we have to wait for the database administrator repair.

  3. Q: The file upload class is used to store uploaded files using move_uploaded_file . By getting the result, the function returns True, and the subsequent method also successfully runs the file name and the path is also stored in the database, but the picture is not found on FTP.
    A: After obtaining the server-side IP and using gethostbyname,gethostname and other functions to obtain the requested server network address and other information. After analysis and judgment and to the administrator, because the FTP service is not scheduled to switch, if the external network access is from the server, then the picture will be present from the server. However, master-slave synchronization will only be synchronized from the primary to the other, not backwards.
    Solution: The official station is not a master-slave design, directly wrote a demo on the official station for testing, the test problem can not be reproduced, then skipped the problem.

  4. Problem: Our process test is completed, the address sent to several colleagues to test, there are sometimes pictures uploaded, but there is no storage, the database is not stored in the picture information.
    A: After many times, the position is that when a single picture is too large, the problem will occur. by file_put_contents output $_files, you know that when a single picture is larger than 3M, $_files becomes an empty array.
    Solution: After the inquiry manual, changed several parameters in the php.ini , the problem is resolved after restarting.

Describe some of the functions and configurations mentioned above

  1. File_put_contents ($filename, $data, $flag)
    A powerful tool for debugging online files, with Var_export ($expression, True) to convert arrays or objects into strings for easy writing to log.
    eg.file_put_contents(‘fl.log‘,var_export($_FILES,true)."\r\n",FILE_APPEND);

  2. Move_uploaded_file ($filename, $destination)
    General file upload class used to be the root of this method, the tmp_name is stored in the given file path. Note that the $destination must be an absolute path.
    eg.move_uploaded_file($tmp_name, LOCAL_ROOT.$save_path);

  3. gethostbyname ($hostname)
    Convert the given hostname to an IPV4 address
    eg.gethostbyname(‘cn.bing.com‘); //202.89.233.103

  4. GetHostName ()
    This function returns the hostname of the current machine, which is the computer name for the computer of the Windows system.

  5. Post_max_size Configuration items in php.ini
    Set the maximum value of a single post data, which must be greater than upload_max_filesize when uploading large files. Usually memory_limit must be greater than post_max_size
    eg.post_max_size = 20M

  6. Upload_max_filesize Configuration items in php.ini
    Set the maximum value for uploading a single file,
    eg.upload_max_filesize = 64M

  7. Get_cfg_var ($option)
    The ability to get the value of a PHP configuration item is especially useful when the server is out of our jurisdiction and does not facilitate excessive interruptions to the administrator.
    eg.get_cfg_var(‘upload_max_filesize‘); //64M

summary

    1. Need to use the server whether the special architecture and so on to consult clearly in advance, the enemy can save a lot of time.

    2. In the local testing must test the limit situation, if I test in the local, with a 10M figure, but also a lot less things.

    3. When you get to any server, it's best to take a look at phpinfo and learn about the PHP version. If the project has the need to upload such operations, you can also use Get_cfg_var first look at the configured size enough.

A few problems with uploading a picture project

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.