Flash can obtain or generate bytearray data of images in various ways, especially Flash Player 10 adds filereference. the load method is much more convenient. The most typical application scenario is to use flash to edit images.
Before Player 10, the common practice is to open an image, choose upload> return image address> load> process> upload.
After Player 10, it will be convenient. Use the load method to open the local image and use the loader. loadbytes method to display the image to complete the first four steps described above.
The final upload is also very simple,CodeAs follows:
VaR uper: urlloader = new urlloader (); var UR: URLRequest = new URLRequest (up_url); Ur. contenttype = 'application/octet-stream'; Ur. method = urlrequestmethod. post; Ur. data = pngencoder. encode (IMG); // see as3corelibuper in reference. load (UR );
PHP receives data and saves the Image Code:
$ UUID = uniqid (); $ Path = sprintf ('upload/% S/', date ('y'), date ('M '), date ('D'); $ file = sprintf('{s}s.png ', $ path, $ UUID); If (! File_exists ($ PATH) {mkdir ($ path, 0755, true);} $ IMG = file_get_contents ('php: // input'); $ fp = fopen ($ file, 'W'); fwrite ($ FP, $ IMG); fclose ($ FP); echo $ file;
References:
- As3corelib
- File_get_contents ()
- Loader. loadbytes ()
- Filereference. Load ()
- Bytearray