Flash 上傳 ByteArray 資料到 php 並儲存為圖片

來源:互聯網
上載者:User

Flash 可以通過各種途徑擷取或產生圖片的 ByteArray 資料, 尤其是 Flash Player 10 增加了 FileReference.load 方法之後, 更是方便了許多, 最典型的一個應用情境就是用 Flash 編輯圖片.

在 player 10 以前, 通常的做法是: 開啟圖片 -> 上傳 -> 返回圖片地址 -> 載入 -> 處理 -> 再上傳.

player 10 以後就方便了, 直接用 load 方法開啟本地圖片, 用 Loader.loadBytes 方法顯示圖片就完成了上面說的前四步.

最終上傳也很簡單, AS 代碼如下:

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); // 見參考中的 as3corelibuper.load(ur);

php 接收資料儲存圖片代碼:

$uuid = uniqid();$path = sprintf('upload/%s/%s/%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;

相關參考:

  • as3corelib
  • file_get_contents()
  • Loader.loadBytes()
  • FileReference.load()
  • ByteArray

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.