Php multiple binary stream images/Files

Source: Internet
Author: User
Tags recode
Php: how to process multiple binary stream images/files 1. this is a functional requirement. the mobile phone interface needs to complete an interface for uploading multiple images, while the webserver needs to accept the binary stream, generate images, save local files, and save the address to the database; 2. at present, we have encountered the following problem: how to get multiple binary streams and change multiple binary streams to the corresponding images. php: how to deal with multiple binary stream images/files?
1. this is a functional requirement. the mobile phone interface needs to complete an interface for uploading multiple images, while the webserver needs to accept the binary stream, generate images, save local files, and save the address to the database;
2. at present, we have encountered the following problem: how to get multiple binary streams, and change multiple binary streams to the corresponding images and save them to the local device?
3. The following describes how to process a binary stream Image:
// Binary data stream
$ File_data = file_get_contents ('php: // input ')? File_get_contents ('php: // input'): gzuncompress ($ GLOBALS ['http _ RAW_POST_DATA ']);
// Save the data stream if it is not empty
If (! Empty ($ file_data )){
$ Save_name = md5 (get_gmtime (). mt_rand (10, 99). ". jpg ";
$ Path = create_dir ();
// Create and write data streams, and save the file
If (@ $ fp = fopen ($ path ['File _ path']. $ save_name, 'W + ')){
Fwrite ($ fp, $ file_data );
Fclose ($ fp );
If (file_exists ($ path ['File _ path']. $ save_name )){
Ajax_return (array ('recode' => "0000", 'MSG '=> "operation successful", 'data' => ""));
} Else {
Ajax_return (array ('recode' => "9001", 'MSG '=> "only jpg, png, jpeg, and gif image types are supported, gif dynamic images do not have dynamic effects after they are uploaded ", 'data' => ""));
}
} Else {
Ajax_return (array ('recode' => "0001", 'MSG '=> "operation failed", 'data' => ''));
}
} Else {
// The data stream is not received
Ajax_return (array ('recode' => "0001", 'MSG '=> "select the image to upload", 'data' => ''));
}
Binary stream Image saves multiple binary stream files and shares them:
------ Solution --------------------
$ _ FILES

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.