Flash uploads bytearray data to PhP and saves it as an image

Source: Internet
Author: User

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

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.