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