PHP multiple binary stream Pictures/files how to handle
1. Functional requirements is this, the mobile phone interface needs to complete a upload multiple images of the interface, and webserver need to accept the binary stream, generate pictures, save local, and save the address of the database;
2. There is now a problem: How to get multiple binary streams and convert multiple binary flows into corresponding pictures to save to local
3. Here's how to receive a binary stream picture processing:
Binary Data Flow
$file _data = file_get_contents (' Php://input ')? file_get_contents (' Php://input '): gzuncompress ($GLOBALS [' http_raw_post_data ']);
The data stream is not empty, then the save operation
if (! empty ($file _data)) {
$save _name=md5 (Get_gmtime (). Mt_rand (10,99)). ". JPG ";
$path =create_dir ();
Create and write a data stream, and then 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 succeeded ', ' data ' = ') ');
} else {
Ajax_return (' recode ' = ' 9001 ', ' msg ' = ' + ' supports only image type uploads in jpg,png,jpeg,gif format, GIF animated images will not be animated after uploading, ' data ' = ' " ));
}
} else {
Ajax_return (Array (' recode ' = ' 0001 ', ' msg ' = ' operation failed ', ' data ' = '));
}
} else {
No data stream received
Ajax_return (Array (' recode ' = ' 0001 ', ' msg ' = "Please select the image to upload", "data ' ="));
}
Binary Stream binary stream Picture save multiple binary stream files saved
Share to:
------Solution--------------------
$_files uses him to read and get the picture data.