Saving an image with AS3 and PHP: 1. PHP
The following PHP code is the code to save an image, which is uploaded using FileReference or is encoded using ByteArray in a Flash movie. The uploadok.php file can handle all the files, uploaded using FileReference, ByteArray or a file form in an HTML document.
다음 코드는 플래시에서 FileReference를 사용한 업로드 또는 ByteArray로 인코딩된 파일을 저장하기 위한 PHP 코드입니다. 이 uploadok.php 파일 하나로 플래시의 FileReference, ByteArray는 물론 HTML문서의 파일 양식을 통한 업로드도 모두 처리가 가능합니다.
Sorry, Japanese translation is not yet available.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <? /** * uploadok.php * ------------ * Author: Han Sanghun (http://hangunsworld.com, hanguns@gmail.com) * Kim Eung (http://eung.co.kr/) * Release Version: 1.0.0 * Date Started: 2007/04/01 * Last Modified: 2008/01/04 * * Determines the name of the saved file. * If "newName" is provided, then uses "newName" as the file's name. * Otherwise, uses the original filename("Filedata.name") as the filename. * * If the original name of the file contains 2-byte characters (e.g. Korean characters), IO error occurs. * To avoid this, use "newName" parameter defined in Flash, rather than the "Filedata.name". * It is possible to assigns a new name in PHP code explicitly. */ $newName = trim($_REQUEST["newName"]); if($newName == ""){ // If newName is not defined, uses Filedata.name as the filename. $newName = $HTTP_POST_FILES['Filedata']['name']; } // Creates "images" folder, if not exist. if(!is_dir("./images")){ mkdir("./images",0777); } // Sets the path in which the uploaded image to be stored. $folderPath = $_SERVER['DOCUMENT_ROOT']."/test/images/"; $newPath = $folderPath.$newName; // Moves the temporary file. @move_uploaded_file($HTTP_POST_FILES['Filedata']['tmp_name'], $newPath); // Returns the saved file path. echo "/test/images/".$newName; ?> |
Special thanks to Kim Eung. He devised the draft of the PHP and AS3 codes. Furthermore, he allowed me to open them to the public.
이 PHP와 AS3 코드의 기틀을 만들고, 이 소스를 공개하는데 흔쾌히 동의하신, 김응 실장님에게 진심으로 감사드립니다.
[...] // http://hangunsworld.com/blog/303 http://hangunsworld.com/blog/307 http://hangunsworld.com/blog/230 http://hangunsworld.com/blog/231 http://hangunsworld.com/blog/232 위 링크들 참고해서 [...]
To get the above running in PHP5 you need to replace $HTTP_POST_FILES with $_FILES and also change <? to <?php
Thanks Han your a life saver.
Thanks for the information about PHP5.
I’ll update the code when I have a free time.