[問題] 有關於圖片從FLASH上傳至MYSQL(amfphp)
各位FLASH大大!!
這幾天忙於做個小程式,遇到以下瓶頸,不知道有沒有哪位大大能幫助解決以下問題
首先是PHP的部分:
<?php
class senddb{
var $dbhost = "localhost";
var $dbname = "image_path";
var $dbuser = "root";
var $dbpass = "123";
var $conn;
var $return = "上傳成功";
function sendpath($S){
$conn = mysql_connect("localhost","root","123");
mysql_select_db("image_path", $conn);
mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER SET UTF8");
mysql_query("insert into dbpath values ('$S')",$conn) or die("mysql error");
return "上傳成功";
}
}
?>
再來是FLASH的部分:
import flash.net.URLRequest;
import flash.net.NetConnection;
import flash.net.Responder;
import flash.system.*;
var uploadURL="http://localhost/upload_uni.php";
var connection:NetConnection;
var responder:Responder;
var frList:FileReferenceList;
var fr:FileReference;
var gateway:String = "http://localhost/amfphp/gateway.php";
var A :String;
responder = new Responder(onResult, onFault);
connection = new NetConnection;
connection.connect(gateway);
function onResult(Result:String):void {
info_txt.appendText(Result+"\n");
}
function onFault(Result:Object):void {
info_txt.appendText("Flash Remoting錯誤\n");
}
function selectFiles(e:Event):void {
var files:Array = frList.fileList;
for (var i:int=0; i<files.length; i++) {
info_txt.appendText(files[i].name +"\n");
}
}
function uploadComplete(e:Event):void {
info_txt.appendText(e.target.name +" 完成上傳\n");
trace("2");
}
browse_btn.addEventListener(MouseEvent.CLICK, browseFiles);
function browseFiles(e:Event):void {
frList = new FileReferenceList;
frList.addEventListener(Event.SELECT, selectFiles);
frList.browse([new FileFilter("Images", "*.jpg;*.gif;*.png")]);
}
upload_btn.addEventListener(MouseEvent.CLICK, uploadStart);
function uploadStart(e:Event):void {
var files:Array = frList.fileList;
if (files.length) {
for (var i:int=0; i<files.length; i++) {
files[i].addEventListener(Event.COMPLETE, uploadComplete);
files[i].upload(new URLRequest(uploadURL));
A = files[i].name;
connection.call("senddb.sendpath",responder,A);
trace("1");
}
}
}
再來是upioad_uni:
<?php
// 圖檔上傳後所欲存放的目錄
$up_dir = "./photo/";
// 若目錄不存在, 則建立之
if(!is_dir($up_dir))
mkdir($up_dir, 0755);
// 上傳的檔案名稱及路徑
$up_file = $up_dir . $_FILES["Filedata"]["name"];
// 將檔案放到設定的目錄內
move_uploaded_file($_FILES["Filedata"]["tmp_name"], $up_file);
// 設定檔案權限
chmod($up_file, 0777);
?>
這個是做上傳圖片時,開啟瀏覽視窗的程式碼,並且把圖片複製存到路徑
我們主要是要做一個FileReference,將圖片存到預先的路徑,最後在FLASH裡面將
圖片的檔名,以正列抓取出來,再透過amfphp至FLASH到MYSQL
但是!!!!!!最出現以下的錯誤error:
TypeError: Error #1009: 無法存取 Null 物件參考的屬性或方法。
at _fla::MainTimeline/uploadStart()
麻煩有哪位神手大大,可以幫助我一下,這已經困擾我很久了Q口Q!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 134.208.96.186
→
09/03 19:02, , 1F
09/03 19:02, 1F
→
09/06 16:45, , 2F
09/06 16:45, 2F
→
09/06 16:46, , 3F
09/06 16:46, 3F
Flash 近期熱門文章
PTT數位生活區 即時熱門文章